多线程与多进程
import threading, multiprocessing
from multiprocessing import Pool
import os, time, random
def loop(i):
x = 0
while True:
x = x ^ 1
def test_threads():
count_cpu=multiprocessing.cpu_count()
for i in range(4):
t = threading.Thread(target=loop)
t.start()
def test_multiprocess():
p = Pool(2)
for i in range(2):
p.apply_async(loop, args=(i,))
print('Waiting for all subprocesses done...')
p.close()
p.join()
if __name__=='__main__':
test_threads()
test_multiprocess()
作者
jnan77
发表于
2017-06-07 18:57:47
,添加在分类
编程语言
下
,并被添加「
python
多线程
高并发
」标签
,最后修改于
2017-06-07 18:57:47
Comments