When we run one thread application it's looks easy. CPython interpreter run one by one bytecode instruction and execute it immediately. But if we start another thread from the first one does it have its own loop consuming bytecode and they share some common memory for synchronization(GIL, etc) or somehow loop from first(main) thread delegate instructions for second? Thing I can't figure out how second thread gets instructions what it need to execute if need to be constantly interpreted. I understand that it won't run in parallel because of GIL, but question about interpreting instructions, does it happens in both threads?
import threading
def thread_function(value):
print(value)
if __name__ == "__main__":
x = threading.Thread(target=thread_function, args=(1,))
x.start()
in which thread print(value)
will be interpreted(main or child)?