1

我正在使用 Ubuntu 12.04 服务器 x64、Python 2.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 来停止它。在这种情况下,将打印以下 KeyboardInterrupt 回溯:https://gist.github.com/max-lobur/8526120#file-traceback

这适用于 ThreadPoolExecutor。

任何反馈表示赞赏

4

1 回答 1

0

我认为这个 KeyboardInterrupt 到达了启动的进程,因为在 ubuntu 和大多数 linux 系统下,新进程是用 fork 创建的——从当前具有相同 stdin、stdout 和 stderr 的进程开始一个新进程。所以 KeyboardInterrupt 可以到达子进程。也许知道更多的人可以添加想法。

于 2014-01-20T21:08:28.217 回答