Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Support cross-thread tracebacking better by using a C extension #2

Open
oremanj opened this issue Jul 26, 2020 · 0 comments
Open

Support cross-thread tracebacking better by using a C extension #2

oremanj opened this issue Jul 26, 2020 · 0 comments

Comments

@oremanj
Copy link
Owner

oremanj commented Jul 26, 2020

  • 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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant