Skip to main content

asy is easy and powerful supervisor for asyncio.

Project description

asy

Version License: MIT

asy is easy and powerful supervisor for asyncio.

Motivation for development

  • Simple cancellation
  • Improve the coordination of async functions between libraries
  • No more programs for execution management
  • Develop specifications like ASGI

Requirement

  • Python 3.8+

Installation

pip install asy

Getting started

Create functions in example.py:

All you have to do is say the magic word token, and you can handle the function's lifetime at will.

import asyncio

# cancelable infinity loop
async def func1(token):
    while not token.is_cancelled:
        await asyncio.sleep(1)
    return "complete func1."


# uncancelable limited loop
async def func2(token):
    for i in range(10):
        await asyncio.sleep(1)
    return f"complete func2.  result: {i}"


# force cancel infinity loop
async def func3():
    while True:
        await asyncio.sleep(1)
    return "complete func3. unreachable code."


# uncancelable limited loop
def func4():
    for i in range(1000):
        ...
    return f"complete func4.  result: {i}"

# from callable
class YourDeamon:
    def __init__(self, value):
        self.value = value

    async def __call__(self, token):
        value = self.value

        while not token.is_cancelled:
            await asyncio.sleep(1)
        return f"complete func5.  result: {value}"

func5 = YourDeamon(1)

# Do not run
# infinity loop
# async def func5():
#     while True:
#         print("waiting")

Run in shell.

python3 -m asy example:func1 example:func2 example:func3 example:func4 example:func5

Run in Python script.

import asy
from example import func1, func2, func3, func4, func5

supervisor = asy.supervise(func1, func2, func3, func4, func5)
supervisor.run()

# or
asy.run(func1, func2, func3, func4, func5)

Let's end the daemon with Ctrl-C and enjoy asy!

Caution

asy is a beta version. Please do not use it in production.

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

asy-0.0.7.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

asy-0.0.7-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file asy-0.0.7.tar.gz.

File metadata

  • Download URL: asy-0.0.7.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.8 CPython/3.8.5 Linux/5.8.0-48-generic

File hashes

Hashes for asy-0.0.7.tar.gz
Algorithm Hash digest
SHA256 129225e1ac395dcbb89dfa204912444bb0048149c3ac5535650683529689d6de
MD5 e7a48991bc75094dd384b6ccf8ffbb9f
BLAKE2b-256 14bf122090ec0d3fdee85947e1ac27363113f97e932b2e41e4e89affbdee2941

See more details on using hashes here.

File details

Details for the file asy-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: asy-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.8 CPython/3.8.5 Linux/5.8.0-48-generic

File hashes

Hashes for asy-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 37a259128be2ae11a361ec741495a5c66739caf45d35029635f7c81a696b4448
MD5 3dccd20652aa08f2ed884aebffb32aad
BLAKE2b-256 1e51974025ab4890f1123e1dc425cdf06e9e7be4afed9f5020b3aa058502d219

See more details on using hashes here.

Supported by

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