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