3 ms·
Just a little fun fact: The GIL absolutely does not prevent all race condition bugs. Threads contending for the GIL can already steal it from each other at unfa
by KeplerBoy 3y ago
Just a little fun fact: The GIL absolutely does not prevent all race condition bugs. Threads contending for the GIL can already steal it from each other at unfavorable times and cause havoc.
- ynik 3y agoIn fact, it prevents very few race condition bugs. Even inside a C extension where the Python API feels like it gives you control over when you release the GIL (with functions you'd have to call explicitly to release the GIL), it turns out that: * any operation that allocates new Python objects might trigger garbage collection * garbage collection may run `__del__` of objects completely unrelated to the currently running C code * `__del__` can be implemented in python, thus releasing the GIL between bytecode instructions Thus there's a lot of (rarely exercised) potential for concurrency even in C extensions that don't explicitly release the GIL themselves. nogil will make it easier to trigger data race bugs, but many of them will already have been theoretically possible before.