多进程
import multiprocessing
import logging
import threading
import datetime
a = '%(asctime)s %(process)s %(processName)s %(threadName)s %(thread)8d %(message)s'
logging.basicConfig(level=logging.INFO, format=a)
def calc(i):
sum = 0
for _ in range(100000000):
sum += 1
ret = i, sum
logging.info(ret)
return ret
ps = []
if __name__ == '__main__':
start = datetime.datetime.now()
for i in range(4):
p = multiprocessing.Process(target=calc, args=(i, ), name='calc-{}'.format(i))
ps.append(p)
p.start()
for p in ps:
p.join()
logging.info('{} {}'.format(p.name, p.exitcode))
delta = (datetime.datetime.now() - start).total_seconds()
print(threading.enumerate(), delta)
print('=====end=====')