Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a helper to dump the task tree / stack tree #927

Open
njsmith opened this issue Feb 13, 2019 · 3 comments
Open

Provide a helper to dump the task tree / stack tree #927

njsmith opened this issue Feb 13, 2019 · 3 comments

Comments

@njsmith
Copy link
Member

njsmith commented Feb 13, 2019

This would be useful in several situations:

  • Possibly we should default to registering a handler for SIGUSR1 (or something similarly innocuous, like SIGIO or SIGSYS), to dump the task tree to stderr. This would help a lot with debugging deadlocks (like @Ninpo has been running into in chat recently)

  • It would be useful for a watchdog thread: Add a blocked task watchdog #591

  • pytest-trio can/should detect frozen tests (Add test timeout support pytest-trio#53), and this would be really useful for diagnosing them (esp. in cases like where the deadlock happens in a remote CI system)

  • It would be useful for tutorials

There's a simple task tree formatter in notes-to-self/.

@oremanj apparently has a version that shows the full stack trace for all tasks. This involves some terrifying hacks to figure out after-the-fact which stack frames created which nurseries, and to work around bpo-32810 (see).

I had a potential idea for how to match up the frames without the terrifying hacks.

For large apps we might want to do some kind of "stack trace compression". Like if you have 1000 tasks, then probably 990 of them have the exact same stack, possibly modulo the last frame or so. Grouping them together based on common prefixes and only printing the prefix once probably makes dumps in this case much more readable.

We don't have to do all of these things in the first version. We can start simpler and iterate.

@carlopires
Copy link

I consider this really important for debugging tasks. Do you have the link to that function which prints the stack trace for all tasks?

@njsmith
Copy link
Member Author

njsmith commented Jun 5, 2019

This is also important for #1085

@njsmith
Copy link
Member Author

njsmith commented Dec 9, 2019

@oremanj uploaded a draft of his code for doing this here: https://github.com/oremanj/trio-monitor

He says:

I was going to remove the pile of CPython-specific hacks and never got around to it
it's also bitrotted a bit at this point, since it looked at _cancel_stack and such

But, still useful as a starting point!

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

No branches or pull requests

3 participants