相关疑难解决方法(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万
查看次数

从线程返回值

我如何让一个线程将一个元组或我选择的任何值返回给Python中的父元素?

python multithreading exit-code python-multithreading

56
推荐指数
6
解决办法
8万
查看次数