Hi,
I made a simple class called TimeTravelLoop for testing asyncio code that 
has sleeps or waits inside of it. 
You might find it useful. It could be found here:

https://github.com/realcr/asyncio_time_travel

Example usage in python code:
import asyncio
from time_travel_util import TimeTravelLoop

SLEEP_TIME = 1000

tloop = TimeTravelLoop()

@asyncio.coroutine
def inner_cor():
        # Sleep for a long time:
        yield from asyncio.sleep(SLEEP_TIME,loop=tloop)

tloop.run_until_complete(inner_cor())

This code won't sleep. It will return immediately.

TimeTravelLoop is based on asyncio.test_utils.TestLoop source code, but it 
has different behaviour.
You don't need a generator or to think about time calculations. You just 
plug in the loop and your asyncio code should work as expected.

Regards,
real.

Reply via email to