python-trio / python-trio/trio

Add a blocked task watchdog

Open
#591 5 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

debugging design discussion polish todo soon user happiness
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.