python-trio / python-trio/trio
Add a blocked task watchdog
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.3k
- Forks
- 431
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 6
Description
In this stackoverflow question, someone gets very confused because they're using time.sleep and never using await, so one of their tasks seems to run correctly but the other doesn't. There's no indication of what's going on. Easy to fix once you know how, but if you don't, then how are you supposed to figure it out?
We could, pretty cheaply, add a watchdog to catch such situations. What I'm imagining is that when entering trio.run, we'd spawn a system task that spins up a thread and watches for the main loop to become stuck. In the main run loop, we'd send it messages occasionally, whenever we (a) start processing a batch of tasks, (b) stop processing a bunch of tasks. If the watchdog thread detects that the time between (a) and (b) exceeds, say, 5 seconds, then it should print an informative message and use the faulthandler module to dump everyone's stack traces. I think this might be cheap enough it could be enabled-by-default.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the code entered by trio.run and the main run loop, focusing on where task batches begin and end. Evaluate the proposed watchdog and faulthandler integration; done means a blocked loop exceeding the proposed threshold produces an informative message and stack traces without disrupting normal operation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100