An event loop for python async
Project description
pasync - A simple event loop for async python
This minimal package is mainly used to explore implementing an async runtime in Python.
Usage
Runner
The main construct that you'll often work with is Runner.
A runner is actually a wrapper around an event loop.
It comes with two flavors: non-blocking runner and blocking runner.
- A blocking runner will run all the tasks till end, blocking the main thread. When given a set of tasks, it will refuse to accept any task in the meaning time.
- A non-blocking runner will run all the tasks in another thread. Unlike a blocking runenr, it can accepts additional tasks in the meaning time.
By default, a runner is blocking.
-
Blocking runner
async def gen_num(n): return n with Runner() as runner: assert runner.run(gen_num(1)) == 1 assert runner.gather(gen_num(1), gen_num(2)) == [1, 2]
-
Non-blocking runner
async def gen_num(n): return n with Runner(non_blocking = True) as runner: assert runner.run(gen_num(1)) == None # Not support returning results yet assert runner.gather(gen_num(1), gen_num(2)) == None # Not support returning results yet
Pitfalls
- Currently, non-blocking runner cannot return results of tasks yet.
This can be worked around by making the top-level task return
None, while all the subtasks's results are consumed inside the top-level task
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pasync-0.3.0.tar.gz.
File metadata
- Download URL: pasync-0.3.0.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/5.15.153.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a49b72262423e593894cfe5a1a7c15b5d8293ceed96658f6b0ced9b5825c66a1
|
|
| MD5 |
4de2c9106166c366598db0eaa532ade4
|
|
| BLAKE2b-256 |
b180bf75f7af5954a8c2a2db9e66023d229ab7c847217f61af0f1d48c645729b
|
File details
Details for the file pasync-0.3.0-py3-none-any.whl.
File metadata
- Download URL: pasync-0.3.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/5.15.153.1-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
adb14047272b8e1defc8c660cd376dfdcf2799eed5f6baa854e0b37dafc5670b
|
|
| MD5 |
a3b35331a3e25fd2f511559f579cf304
|
|
| BLAKE2b-256 |
8be4605f1d8d3acad0d333e9d61d67cbe0a57b12ab8e32d77cd5a6fecd881cc5
|