Tools for wrapping existing synchronous libraries into Python3's asyncio framework.
Project description
Assume that you have some existing libraries with blocking methods:
def foo_sync(x, a, b): """Some existing library methods. Sleeps for x seconds and returns a + b.""" time.sleep(x) return a + b
And you are writing a program in Python3’s asyncio framework. To use the blocking library, one way is to use a thread pool. This library provides another option:
# Wraps foo_sync() into foo_async() to use in asyncio framework. time.sleep = aiowrap.wrap_async(asyncio.sleep) foo_async = aiowrap.wrap_sync(foo_sync)
Now you have an asynchronous, non-blocking version of the method, you can call it inside your favourite coroutine:
async def main(): print(await foo_async(1, 2, 3))
The source code of this example can be found at example/sleep.py.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aiowrap-0.1.1.tar.gz
(1.6 kB
view details)
File details
Details for the file aiowrap-0.1.1.tar.gz
.
File metadata
- Download URL: aiowrap-0.1.1.tar.gz
- Upload date:
- Size: 1.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0066270a9f61403e76d47ebb0023f793e28336e0ca45b513ebcc088cc41e22d |
|
MD5 | 215990720f66ea3888b6753d52f40fc0 |
|
BLAKE2b-256 | 56b037b565f801d9b6f7badf16920f3c69bd2b5cb3e6964a7eb259ddb90eabaf |