Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Asyncio Time Travel Loop

Project Description
Asyncio Time Travel Loop


Asyncio Time Travel Loop allows you to test asyncio code that waits or sleeps,
without actually waiting or sleeping.

At the same time, you don't have to bother thinking about how the time
advances. Your code should work exactly the same with TimeTravelLoop as it works
with a normal asyncio events loop.

Example: Assume that you have a code that waits 1000 seconds, and you want to
tests that code. Instead of actually waiting 1000 seconds, you could use

import asyncio
from asyncio_time_travel import TimeTravelLoop


tloop = TimeTravelLoop()

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


This code completes immediately.

See some of the [tests]( for more advanced examples of what TimeTravelLoop can do.

pip install --pre asyncio-time-travel
You can also find the package at .


Run (Inside asyncio_time_travel dir):

If you haven't yet heard of [py.test](, it's your lucky day :)

How does this work?

TimeTravelLoop source is based on the source code of

For each _run_once iteration of the loop, the following is done:
- Loop events are executed.
- Time is advanced to the closest scheduled event.

Using this method your code never waits, and at the same time the events
execute in the correct order.


TimeTravelLoop is meant to be used with your tests, not for production code. In
particular, if your loop interacts with external events, bending time is not a
good idea (Time will advance differently outside of your loop).

Further work

- The code might have bugs. If you find any issues, don't hesitate to fork or
open an issue.

- It might be possible to integrate this code into asyncio.test_utils in some
Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
asyncio_time_travel-0.1.4-py3-none-any.whl (6.4 kB) Copy SHA256 Checksum SHA256 py3 Wheel Dec 23, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting