Asyncio Time Travel Loop (For testing)

45 views
Skip to first unread message

rea...@gmail.com

unread,
Apr 6, 2015, 12:04:20 PM4/6/15
to python...@googlegroups.com
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.

Rémy Hubscher

unread,
Apr 9, 2015, 11:16:08 AM4/9/15
to python...@googlegroups.com
Neat, thanks for the information.
Reply all
Reply to author
Forward
0 new messages