V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  bihuchao  ›  全部回复第 2 页 / 共 2 页
回复总数  30
1  2  
2019-01-07 11:19:46 +08:00
回复了 freedom1988 创建的主题 推广 [2019 年首赠] 送 6 本《程序员面试笔试真题与解析》
2019-01-06 16:23:54 +08:00
回复了 tqknight 创建的主题 Python apply_async 多进程异步调用,子任务不执行,居然没找到原因
multiprocessing 中的 Queue 不能被序列化。
目的应该是这样吧
``` Python
#! /usr/bin/python3

import time
import random
import multiprocessing

queue = multiprocessing.Queue()

def perform_task(id):
print("{0}# process start".format(id))
begin = time.time()
time.sleep(random.random()*5)
print("{0}# process end".format(id))

res = "{0}# process time : {1}".format(id, time.time()-begin)
print(res)

queue.put(res)

return

if __name__ == "__main__":
poolCount = 5
pool = multiprocessing.Pool(poolCount)

for i in range(poolCount):
pool.apply_async(perform_task, args=(i, ))

pool.close()
pool.join()

print("End tasking, print results:")

while True:
res = queue.get()
print(res)
if queue.empty():
break

```
执行结果:
```
0# process start
1# process start
2# process start
3# process start
4# process start
0# process end
0# process time : 0.5990872383117676
1# process end
1# process time : 2.662280559539795
3# process end
3# process time : 3.903242826461792
2# process end
2# process time : 4.440236330032349
4# process end
4# process time : 4.543649435043335
End tasking, print results:
0# process time : 0.5990872383117676
1# process time : 2.662280559539795
3# process time : 3.903242826461792
2# process time : 4.440236330032349
4# process time : 4.543649435043335
```
2018-08-17 11:20:15 +08:00
回复了 yanxijian 创建的主题 程序员 C++/Qt 客户端想转后台开发,是 Linux C++ 还是 Go 比较好呢?
GO 是真的很好用
2018-07-02 20:49:23 +08:00
回复了 doggg 创建的主题 全球工单系统 微信 PC:最不厚道的 1px
hah
2018-06-12 23:34:26 +08:00
回复了 zuohuadong 创建的主题 Linux 开发环境从 windows 到 Linux 攻略
果断收藏。
2018-06-10 16:10:34 +08:00
回复了 tamlok 创建的主题 程序员 支付宝淘宝是怎么做到这么卡的
小米 6,买来只为了所有应用都不卡。
2018-06-10 16:09:06 +08:00
回复了 doubleflower 创建的主题 全球工单系统 微博竟然评论能给自已点个赞
我一直是这样的。
不知道是不是真的。
1  2  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3163 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 26ms · UTC 00:35 · PVG 08:35 · LAX 17:35 · JFK 20:35
Developed with CodeLauncher
♥ Do have faith in what you're doing.