相关疑难解决方法(0)

如何从python中的线程获取返回值?

如何获取foo从线程目标返回的值?

from threading import Thread

def foo(bar):
    print('hello {}'.format(bar))
    return 'foo'

thread = Thread(target=foo, args=('world!',))
thread.start()
return_value = thread.join()
Run Code Online (Sandbox Code Playgroud)

如上所示,"一种显而易见的方法"不起作用:'foo'返回'foo'.

python multithreading

289
推荐指数
15
解决办法
28万
查看次数

标签 统计

multithreading ×1

python ×1