Skip to content
Advertisement

How to get the return value from a thread?

The function foo below returns a string 'foo'. How can I get the value 'foo' which is returned from the thread’s target?

JavaScript

The “one obvious way to do it”, shown above, doesn’t work: thread.join() returned None.

Advertisement

Answer

In Python 3.2+, stdlib concurrent.futures module provides a higher level API to threading, including passing return values or exceptions from a worker thread back to the main thread:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement