You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
In principle, we can determine the current greenlet in another thread by looking at the "__greenlet_ts_curkey" entry in the thread state dict. In practice, the thread state structure is impossible to access safely from Python because there's no way to keep it from being freed while you're looking at it. (In C, you can just refuse to release the GIL.)
We can also use C's ability to hold the GIL to extract consistent tracebacks from other threads in general, avoiding the thing where we think the coroutine is running but it gets suspended before we call sys._current_frames().
We could read thread-locals of other threads, which would help with "where even is the Trio runner anyway" for cross-thread task tree dumping (eg on infinite loop).
Most of this won't work on pypy. pypy greenlet is a thoroughly non-magical module that uses a threading.local for its "current" knowledge, so knowing how to read other threads' locals would solve both 1 and 3, and we might be able to solve 2 using setcheckinterval(), since pypy uses a different GIL approach than cpython does (it's like old cpython). Also, we don't have as much of a need to identify the current greenlet on pypy anyway, since pypy's greenlets don't break f_back like cpython's do.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
In principle, we can determine the current greenlet in another thread by looking at the
"__greenlet_ts_curkey"
entry in the thread state dict. In practice, the thread state structure is impossible to access safely from Python because there's no way to keep it from being freed while you're looking at it. (In C, you can just refuse to release the GIL.)We can also use C's ability to hold the GIL to extract consistent tracebacks from other threads in general, avoiding the thing where we think the coroutine is running but it gets suspended before we call sys._current_frames().
We could read thread-locals of other threads, which would help with "where even is the Trio runner anyway" for cross-thread task tree dumping (eg on infinite loop).
Most of this won't work on pypy. pypy greenlet is a thoroughly non-magical module that uses a threading.local for its "current" knowledge, so knowing how to read other threads' locals would solve both 1 and 3, and we might be able to solve 2 using setcheckinterval(), since pypy uses a different GIL approach than cpython does (it's like old cpython). Also, we don't have as much of a need to identify the current greenlet on pypy anyway, since pypy's greenlets don't break f_back like cpython's do.
The text was updated successfully, but these errors were encountered: