Locking the global Python interpreter means that only one thread can be active in the interpreter at any given time. However, as soon as control is transferred to extension C, another thread may be active in the interpreter. You can create multiple threads, and nothing prevents the thread from being interrupted in the middle of a critical section. N
in thread-safe code it can be implemented in the interpreter, so nothing about code running inside the interpreter is essentially thread-safe. In C or Pyrex modules, code can modify the data structures that are visible to python code. Natural code can, of course, also have problems with threads with their own data structures.
You cannot guarantee the safety of the stream outside of the proper construction and synchronization - the GIL on the python interpreter will not significantly change this.
source share