Skip to main content

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

  1. 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

pasync-0.3.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pasync-0.3.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

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

Hashes for pasync-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a49b72262423e593894cfe5a1a7c15b5d8293ceed96658f6b0ced9b5825c66a1
MD5 4de2c9106166c366598db0eaa532ade4
BLAKE2b-256 b180bf75f7af5954a8c2a2db9e66023d229ab7c847217f61af0f1d48c645729b

See more details on using hashes here.

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

Hashes for pasync-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 adb14047272b8e1defc8c660cd376dfdcf2799eed5f6baa854e0b37dafc5670b
MD5 a3b35331a3e25fd2f511559f579cf304
BLAKE2b-256 8be4605f1d8d3acad0d333e9d61d67cbe0a57b12ab8e32d77cd5a6fecd881cc5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page