请教 multiprocessing 问题,在 window7 下运行可以正常打印, ubuntu 运行一会就卡死了。

2020-08-21 22:13:58 +08:00
 naldo0193
在 window7 下运行可以正常打印,ubuntu 运行一会就卡死了。


import time,os

from multiprocessing import Manager,Pool



def test_try(multiprocess_queue):
print(os.getpid())
check_multiprocess_queue = multiprocess_queue.empty()
if check_multiprocess_queue:
print('队列为空')
else:
each_data = multiprocess_queue.get()

print(os.getpid())


if __name__ == '__main__':
while True:
multiprocess_queue = Manager().Queue()
multiprocess_queue.put('a')
pool = Pool(processes=2) # 最大核数
# 异步进程
for d in range(2):
pool.apply_async(func=test_try, args=(multiprocess_queue,))

pool.close()
pool.join()
1463 次点击
所在节点    Python
3 条回复
AlohaV2
2020-08-21 22:27:21 +08:00
没有对齐对于 python 代码来说是很致命的,比如我不知道 while True 的作用范围是什么
dingwen07
2020-08-21 22:47:57 +08:00
你这没缩进让人怎么看
lzp729
2020-08-21 22:52:32 +08:00
linux 默认是 fork

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/700378

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX