V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
snachx
V2EX  ›  问与答

关于 python 的 ThreadPoolExecutor 使用,是我理解错了吗?

  •  
  •   snachx · 2016-07-21 15:46:04 +08:00 · 1775 次点击
    这是一个创建于 2849 天前的主题,其中的信息可能已经有所发展或是发生改变。

    看 concurrent.futures 的文档,讲 ThreadPoolExecutor 的时候有一段

    def wait_on_future():
        f = executor.submit(pow, 5, 2)
        # This will never complete because there is only one worker thread and
        # it is executing this function.
        print(f.result())
    
    executor = ThreadPoolExecutor(max_workers=1)
    executor.submit(wait_on_future)
    

    看注释的意思应该是说如果 max_workers > 1 的话就不会有问题吧?可是为什么我把 max_workers 设为大于 1 的值, f 的状态还是一直卡在 pending 没输出结果呢? macOS 和 Linux 上都试过了。

    1 条回复    2016-07-22 20:30:42 +08:00
    snachx
        1
    snachx  
    OP
       2016-07-22 20:30:42 +08:00
    趁晚上自己顶一下...
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3013 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 15:14 · PVG 23:14 · LAX 08:14 · JFK 11:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.