-
Why does this program deadlock with python version 3.13t and feature
My understanding of freethreaded python is that multiple threads should be able to attach to the python interpreter at once, so I would expect this program to succeed. But in this example if a thread spawned while being attached tries to attach, it causes the program to deadlock. Is this expected behavior? Or an issue somewhere? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Can you give more details about how you have set up your environment to use 3.13t? Can you validate a free-threaded interpreter is being used? The GIL may also be re-enabled if an incompatible module is loaded; have you tried with |
Beta Was this translation helpful? Give feedback.
-
A related question for me is what is the overhead of `py.allow_threads()`
in a free-threaded build. We know that in GIL builds it can be quite
substantial (
pyca/cryptography#11900 (comment))
…On Mon, Dec 2, 2024 at 1:25 PM Nathan Goldbaum ***@***.***> wrote:
I think the documentation probably needs better advice about exactly when
py.allow_threads is needed and also to mention that deadlocks are
possible because the interpreter can trigger global synchronization events
for various reasons.
I'll try to tackle that this week.
—
Reply to this email directly, view it on GitHub
<#4738 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAAGBCQVJXFEZZQJ6BVS3D2DSQZ5AVCNFSM6AAAAABSTUZGUSVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCNBTHE4TEMY>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
All that is necessary for evil to succeed is for good people to do nothing.
|
Beta Was this translation helpful? Give feedback.
This is expected behavior. In the original example, you need
py.allow_threads
around thejoin()
call. In @davidhewitt's example, you need apy.allow_threads
around thebarrier.wait()
.There's a brief description about this in the C API "howto". You need to use the GIL state APIs in the same places as you would use them in the default (with GIL) build.
Although free threading allows multiple threads to be attached to the Python VM at once, there are some times where a single thread requires exclusive access (a stop-the-world pause). Here are a few examples: