IO-intensive tasks sub-process solutions
# Test1 IO-intensive tasks (Act 1: Open the child process solutions)
from multiprocessing Import Process
Import Time
DEF Task ():
the time.sleep ( 2 )
IF __name__ == ' __main__ ' :
Start = time.time ()
LST = []
# for opening the sub-process 100
for I in Range (100 ):
p = process (target = Task)
p.start ()
# p-child process objects stored list, this time as a list of all instances of acceptable container out of objects
lst.append (the p-)
for the p-in lst:
p.join()
end = time.time()
print(end-start)
# 耗时 2.1534228324890137
IO-intensive tasks task sub-process solution
from Threading Import the Thread
Import Time
DEF Task ():
the time.sleep ( 2 )
IF the __name__ == ' __main__ ' :
Start = the time.time ()
LST = []
# for opening the sub-process 100
for I in Range (100 ) :
p = the Thread (target = Task)
p.start ()
# p-sub process objects stored in the list, this time to accept the list as a container for all instances of an object out of
lst.append (p)
for p in LST:
p.join ()
End = the time.time ()
Print (Start-End) # Processed 2.0103108882904053