python-trio / python-trio/trio

Please allow keyword arguments of deterministic scheduling and random-value generation

Open
#2,675 2 comments 0 reactions 0 assignees View on GitHub

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.