Answer the question
In order to leave comments, you need to log in
How to return the value of a function in a thread?
There is a code:
class get:
def info(msgID):
r = "321"
print("def " + r)
return(r)
class qwe:
async def qqq(msgID):
th = Thread(target=get.info, args=(msgID, ))
th.start()
print(th.join())
Answer the question
In order to leave comments, you need to log in
" As join() always returns None... "
join() never returns anything other than None at all.
It's better to tell the thread where it should put the result.
For example, so
def thread_body(arg, target):
result = "foo" + arg
target.append(result)
def call_thread(arg):
target = []
th = threading.Thread(target=thread_body, args=(arg, target))
th.start()
th.join()
return target[0]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question