Skip to content

Commit

Permalink
Merge pull request #1580 from palkeo/master
Browse files Browse the repository at this point in the history
  • Loading branch information
pquentin authored Jun 8, 2020
2 parents 33ab557 + a67aaf6 commit c32b1bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions trio/_core/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2076,15 +2076,20 @@ def unrolled_run(runner, async_fn, args, host_uses_signal_set_wakeup_fd=False):
# tie-breaker and the non-deterministic ordering of
# task._notify_queues.)
batch = list(runner.runq)
runner.runq.clear()
if _ALLOW_DETERMINISTIC_SCHEDULING:
# We're running under Hypothesis, and pytest-trio has patched
# this in to make the scheduler deterministic and avoid flaky
# tests. It's not worth the (small) performance cost in normal
# operation, since we'll shuffle the list and _r is only
# seeded for tests.
batch.sort(key=lambda t: t._counter)
runner.runq.clear()
_r.shuffle(batch)
_r.shuffle(batch)
else:
# 50% chance of reversing the batch, this way each task
# can appear before/after any other task.
if _r.random() < 0.5:
batch.reverse()
while batch:
task = batch.pop()
GLOBAL_RUN_CONTEXT.task = task
Expand Down
2 changes: 1 addition & 1 deletion trio/tests/test_scheduler_determinism.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async def scheduler_trace():
trace = []

async def tracer(name):
for i in range(10):
for i in range(50):
trace.append((name, i))
await trio.sleep(0)

Expand Down

0 comments on commit c32b1bb

Please sign in to comment.