首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用concurrent.futures时不打印任何内容

使用concurrent.futures时不打印任何内容
EN

Stack Overflow用户
提问于 2021-06-06 20:33:22
回答 1查看 98关注 0票数 0

我想让一个进程并行运行,所以我使用concurrent.futures。问题是它不执行函数hello()。

代码语言:javascript
复制
import time
import concurrent.futures
def hello(name):
    print(f'hello {name}')
    sleep(1)

if __name__ == "__main__":
    t1=time.perf_counter()
    names=["Jack","John","Lily","Stephen"]


    with concurrent.futures.ProcessPoolExecutor() as executor:
        executor.map(hello,names)

    t2=time.perf_counter()
    print(f'{t2-t1} seconds')

输出

代码语言:javascript
复制
0.5415315 seconds
EN

回答 1

Stack Overflow用户

发布于 2021-06-07 12:56:43

浏览完concurrent.futures documentation后,我发现ProcessPoolExecutor在交互式解释器中不起作用。因此,您需要创建一个文件,并通过命令提示符/bash shell运行它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67859171

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档