python-trio / python-trio/trio
Please allow keyword arguments of deterministic scheduling and random-value generation
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.3k
- Forks
- 431
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 6
Description
Deterministic scheduling is a very desirable characteristic for user code testing where external interactions can be mocked-up. In my view, this is one of the major advantages of trio over asyncio. Deterministic scheduling is controlled by the following two lines in core/_run.py:
_ALLOW_DETERMINISTIC_SCHEDULING: FinalT = False
_r = random.Random()
Right now these are monkey-patched by pytest-trio, but not all user code uses pytest-trio to create test runners (for example, anyio). Downstream users are thus left to monkey-patch the runner factory themselves.
It would be nice if Trio's constructor had these as keyword arguments. I think separate arguments would be best, because I can think of cases where one might wish to control random-value generation without incurring the performance hit of deterministic scheduling.
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 in core/_run.py by reading _ALLOW_DETERMINISTIC_SCHEDULING and _r, then trace the Trio runner or constructor entry point that controls them. Confirm how pytest-trio currently monkey-patches these values and define completion as independently configurable keyword arguments for deterministic scheduling and random-value generation, without requiring downstream monkey-patching.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100