You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice with a documented way to make scheduling deterministic when running in guest mode. I have a use case with no I/O, where we value deterministic behavior.
Example: The following program sometimes prints 0 1 2 3 4, and sometimes prints 4 3 2 1 0.
from queue import SimpleQueue, Empty
import trio
class Loop:
def __init__(self):
self.q = SimpleQueue()
def process_work(self):
while True:
try:
f = self.q.get_nowait()
except Empty:
return
f()
loop = Loop()
async def task(i):
print(i)
async def run_nursery():
async with trio.open_nursery() as nursery:
for i in range(5):
nursery.start_soon(task, i)
trio.lowlevel.start_guest_run(
run_nursery,
run_sync_soon_threadsafe=loop.q.put,
done_callback=lambda _: None)
loop.process_work()
I have a hideously crude workaround to suppress the problem for now:
trio._core._run._r.random = lambda: 1
but it would be nice with a supported way to do this.
The text was updated successfully, but these errors were encountered:
It would be nice with a documented way to make scheduling deterministic when running in guest mode. I have a use case with no I/O, where we value deterministic behavior.
Example: The following program sometimes prints
0 1 2 3 4
, and sometimes prints4 3 2 1 0
.I have a hideously crude workaround to suppress the problem for now:
but it would be nice with a supported way to do this.
The text was updated successfully, but these errors were encountered: