Can someone explain how the Python threading works? Does thread.start() not run the target function to completion before switching back to another context like main below?
import time
import threading
def threadfunc():
# time.sleep(1)
print('thread print 1', flush=True)
print('thread print 2', flush=True)
#time.sleep(1)
print('before thread', flush=True)
thread1 = threading.Thread(target=threadfunc)
thread1.start()
print('after thread', flush=True)
Output:
before thread
thread print 1
after thread
thread print 2 #shouldn't this be after "print 1"?