程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Django restframework program enables multi process processing

編輯:Python

django As a background operation and maintenance , Sometimes it may involve multi process concurrency , This is the time django Multiple programs will be opened and consistent with the process pool subprogram
In my views.py Add a function to a function module , Then call the following code

from multiprocessing import Pool
import time,datetime,os
def sayhi():
print(f' The current operating system ID:{
os.getpid()}')
time.sleep(10)

views.py A design call to a web page

pool = multiprocessing.Pool(5)
for i in range(50):
pool.apply_async(sayhi,args=())
pool.close()
pool.join()

Click on our page to see django increase 5 A process

(python38) [[email protected] django-restframework-test-master]# ps -ef|grep python|grep virtual
root 1621 1487 4 20:03 pts/0 00:00:10 /virtualenv/python38/bin/python manage.py runserver 192.168.56.150:8000
root 1786 1621 0 20:07 pts/0 00:00:00 /virtualenv/python38/bin/python manage.py runserver 192.168.56.150:8000
root 1787 1621 0 20:07 pts/0 00:00:00 /virtualenv/python38/bin/python manage.py runserver 192.168.56.150:8000
root 1788 1621 0 20:07 pts/0 00:00:00 /virtualenv/python38/bin/python manage.py runserver 192.168.56.150:8000
root 1789 1621 0 20:07 pts/0 00:00:00 /virtualenv/python38/bin/python manage.py runserver 192.168.56.150:8000
root 1790 1621 0 20:07 pts/0 00:00:00 /virtualenv/python38/bin/python manage.py runserver 192.168.56.150:8000
 The current operating system ID:1921
The current operating system ID:1922
The current operating system ID:1923
The current operating system ID:1924
The current operating system ID:1925
The current operating system ID:1921
The current operating system ID:1925
The current operating system ID:1922
The current operating system ID:1923
The current operating system ID:1924
The current operating system ID:1922
The current operating system ID:1921
The current operating system ID:1925
The current operating system ID:1923
The current operating system ID:1924
The current operating system ID:1921
The current operating system ID:1923
The current operating system ID:1924
The current operating system ID:1922
The current operating system ID:1925
The current operating system ID:1923
The current operating system ID:1925
The current operating system ID:1922
The current operating system ID:1921
The current operating system ID:1924
The current operating system ID:1921
The current operating system ID:1924
The current operating system ID:1925
The current operating system ID:1922
The current operating system ID:1923
The current operating system ID:1924
The current operating system ID:1925
The current operating system ID:1922
The current operating system ID:1921
The current operating system ID:1923
The current operating system ID:1924
The current operating system ID:1922
The current operating system ID:1925
The current operating system ID:1921
The current operating system ID:1923
The current operating system ID:1924
The current operating system ID:1922
The current operating system ID:1921
The current operating system ID:1923
The current operating system ID:1925
The current operating system ID:1922
The current operating system ID:1925
The current operating system ID:1924
The current operating system ID:1923
The current operating system ID:1921

sayhi This function is also 5 A process ID alternate , Verification is OK


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved