isFrozen() and check-then-act races
isFrozen() and check-then-act races
Posted Jul 24, 2025 17:23 UTC (Thu) by NYKevin (subscriber, #129325)In reply to: isFrozen() and check-then-act races by luked
Parent article: Deep immutability for Python
Even with the GIL, it is entirely possible for the interpreter to release it and switch to a different thread right after you return from isfrozen(). See e.g. sys.setswitchinterval(). The GIL is designed to protect C extensions and CPython's internals from concurrency, not to magick away arbitrary threading problems in pure Python code.