This works fine:
def myfunc():
print('inside myfunc')
t = threading.Thread(target=myfunc)
t.start()
t.join()
print('done')
However this, while apparently creating and executing the thread properly:
def myfunc():
print('inside myfunc')
t = threading.Thread(target=myfunc).start()
t.join()
print('done')
Generates the following fatal error when it hits join():
AttributeError: 'NoneType' object has no attribute 'join'
I would have thought that these statements are equivalent. What is different?
t = threading.Thread(target=myfunc).start()
threading.Thread(target=myfunc) returns a thread object, However object.start() returns None. That's why there is an AttributeError.