No project description provided
Project description
timeless_loop
timeless_loop is a Python library that provides a custom asyncio event loop, allowing you to freeze time and avoid pesky delays while writing or testing async code. It does so by defining a subclass of the built-in SelectorEventLoop
, which behaves nearly identically to the real one. It differs in that it does not actually wait for any time to pass; instead, it simply advances the loop's internal clock to the exact time of execution of the next scheduled callback when there are no immediately ready loop callbacks available.
In addition, timeless_loop has the ability to detect and raise an exception when deadlocks occur in asyncio code. This helps to prevent your program from getting stuck in an infinite loop and allows you to easily track down and fix any issues. This is experimental, and thus subject to bugs. It is disabled by default.
Installation
timeless_loop is available on PyPI and can be installed with poetry
, pip
, or your favorite package manager.
pip install timeless_loop
Usage
The recommended way of setting the TimelessEventLoop is through setring the loop policy with asyncio.set_event_loop_policy
. It can be used as follows:
import asyncio
from timeless_loop import TimelessEventLoopPolicy
async def main():
# code here will run on the TimelessEventLoop
pass
asyncio.set_event_loop_policy(TimelessEventLoopPolicy(raise_on_deadlock=False))
asyncio.run(main())
Alternatively, you can directly create and use a TimelessEventLoop
instance:
import asyncio
from timeless_loop import TimelessEventLoop
async def main():
# code here will run on the TimelessEventLoop
pass
loop = TimelessEventLoop(raise_on_deadlock=False)
loop.run_until_complete(main())
If a deadlock is detected by the TimelessEventLoop, a DeadlockError
will be raised if the loop was created with the raise_on_deadlock flag set to True.
License
timeless_loop is licensed under the MIT License. See the LICENSE file for more details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file timeless_loop-0.1.1.tar.gz
.
File metadata
- Download URL: timeless_loop-0.1.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.10.8 Linux/6.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b530f02de3ebc6a18f98f0a5eb52006e57f11f6db7b3600d232b0aba54ff6cb |
|
MD5 | a218a7779eb798f43b3a4aad89d06dcc |
|
BLAKE2b-256 | e40c8ebd79057a7bdc05771d22129a57ca5d33e97454b34619c6050e300bfea2 |
File details
Details for the file timeless_loop-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: timeless_loop-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.10.8 Linux/6.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b4cbe757feff7696cf8f7196c6d85bf563c9da0326e16e40d9c320a2316761d |
|
MD5 | ed3acdbddc17756957055731f80d73f2 |
|
BLAKE2b-256 | 9ffb47e0039c1e48da20198d4ff8a6b041fa9937431ed9c794a19b7f8b9d848c |