使用时eventlet挂起期货.ProcessPoolExecu

2024-09-30 18:20:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是Ubuntu12.04Serverx64,Python2.7.3,futures==2.1.5,eventlet==0.14.0

有人碰到同样的问题吗?在

import eventlet
import futures
import random

# eventlet.monkey_patch() # Uncomment this line and it will hang!

def test():
    if random.choice((True, False)):
        raise Exception()
    print "OK this time"

def done(f):
    print "done callback!"

def main():
    with futures.ProcessPoolExecutor() as executor:
        fu = []
        for i in xrange(6):
            f = executor.submit(test)
            f.add_done_callback(done)
            fu.append(f)
        futures.wait(fu, return_when=futures.ALL_COMPLETED)

if __name__ == '__main__':
    main()

如果取消注释该行,则此代码将挂起。我只能通过按Ctrl+C来停止它。在这种情况下,将打印以下键盘中断回溯:https://gist.github.com/max-lobur/8526120#file-traceback

这在ThreadPoolExecutor中可以很好地工作。在

欢迎任何反馈


Tags: testimportifmaindefcallbackrandomthis
1条回答
网友
1楼 · 发布于 2024-09-30 18:20:29

我认为这个键盘中断到达启动的进程,因为在ubuntu和大多数linux系统下,新进程是用fork创建的——从当前进程开始,使用相同的stdin和stdout和stderr。因此键盘中断可以到达子进程。也许知道更多的人可以增加一些想法。在

相关问题 更多 >