👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
The function foo
below returns a string "foo"
. How can I get the value "foo"
which is returned from the thread"s target?
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()
The "one obvious way to do it", shown above, doesn"t work: thread.join()
returned None
.
👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from How to get the return value from a thread in python?, check other _thread Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano How to get the return value from a thread in python?
- Deutsch How to get the return value from a thread in python?
- Français How to get the return value from a thread in python?
- Español How to get the return value from a thread in python?
- Türk How to get the return value from a thread in python?
- Русский How to get the return value from a thread in python?
- Português How to get the return value from a thread in python?
- Polski How to get the return value from a thread in python?
- Nederlandse How to get the return value from a thread in python?
- 中文 How to get the return value from a thread in python?
- 한국어 How to get the return value from a thread in python?
- 日本語 How to get the return value from a thread in python?
- हिन्दी How to get the return value from a thread in python?
Rome | 2023-03-23
Python functions is always a bit confusing 😭 How to get the return value from a thread in python? is not the only problem I encountered. Will use it in my bachelor thesis
Vigrinia | 2023-03-23
I was preparing for my coding interview, thanks for clarifying this - How to get the return value from a thread in python? in Python is not the simplest one. Will get back tomorrow with feedback
Warsaw | 2023-03-23
Maybe there are another answers? What How to get the return value from a thread in python? exactly means?. I am just not quite sure it is the best method