multiprocessing module in python

 

What is the multiprocess module for?

Answer: Using multiprocessing can create child processes in the main process.

#This module is basically similar to the Threading module.

  • First of all, it needs to be explained that the multi-threaded function you are using cannot have return. For example, if you want to multi-thread the job function, you cannot have return in the job function.

Case:

#!usr/bin/env python
#encding:utf-8
#by i3ekr

import multiprocessing,time

def job(q,a):
    time.sleep(3)
    print 'this is test...%s'%(a)


start = time.time()
p1 = multiprocessing.Process(target=job,args=(q,1))
p2 = multiprocessing.Process(target=job,args=(q,2))
p1.start()
p2.start()
p1.join()
p2.join()
end = time.time()
print("run time is %s"%(end-start))

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324986313&siteId=291194637