Skip to main content

aioerl

PyPI version

aioerl is a python library that mimics the philosophy of Erlang's processes with asyncio tasks.

Implements the following ideas:

  • Each process has a mailbox: a queue to receive messages from other processes.
  • Message passing: processes communicate entirely with messages (from the point of view of the developer)
  • Supervisor/monitors: processes can monitor other processes (when a process dies or crashes, sends a message to its supervisor with the exit reason or the exception)

Why?

asyncio is awesome and built-in structures like asyncio.Queue are great for communicating between tasks but is hard to manage errors.

With aioerl, a process just waits for incoming messages from other processes and decides what to do for each event (see example).

Quickstart

Requirements: Python 3.7+

Installation:

pip install aioerl

Example

from aioerl import receive
from aioerl import reply
from aioerl import send
from aioerl import spawn

import asyncio


async def ping_pong():
    while m := await receive(timeout=10):
        if m.is_ok:
            if m.body == "ping":
                await reply("pong")
            else:
                raise Exception("Invalid message body")
        elif m.is_timeout:
            return  # terminate process


async def main():
    p = await spawn(ping_pong())

    await send(p, "ping")
    print(await receive())  # Message(sender=<Proc:Task-2>, event='ok', body='pong')

    await send(p, "pang")
    print(await receive())  # Message(sender=<Proc:Task-2>, event='err', body=Exception('Invalid message body'))

    await send(p, "ping")
    print(await receive())  # Message(sender=<Proc:Task-2>, event='exit', body='noproc')


if __name__ == "__main__":
    asyncio.run(main())

TODO:

Lot of things!

Metadata

Release files for aioerl 0.0.20200813

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aioerl 0.0.20200813
File Size Uploaded
aioerl-0.0.20200813.tar.gz 17.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aioerl 0.0.20200813
File Interpreter ABI Platform
aioerl-0.0.20200813-py3-none-any.whl Python 3 none any Details

Total release size: 34.9 kB

Release files / aioerl-0.0.20200813.tar.gz

Download URL aioerl-0.0.20200813.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b25fd8825385aaf9e264897658b0a8c73503c93ac931b3ee751d0fc471a9a1f1
BLAKE2b-256 checksum
How to use checksums
304e4c6b60d62e825057b0ff3707a80a4b1c74532343f7a6ede45e99e3168780
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.9 CPython/3.8.2 Linux/4.15.0-112-generic

Release files / aioerl-0.0.20200813-py3-none-any.whl

Download URL aioerl-0.0.20200813-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da6649f6343b84773ec13975c2463220c4c695fb04f1074bf374096a6ed0a383
BLAKE2b-256 checksum
How to use checksums
5edf17a4e5cb8bc76f3e7cd3cc5a6abeff1803c70ce49fccf8b0bba30596e7ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.9 CPython/3.8.2 Linux/4.15.0-112-generic

Release history Release notifications | RSS feed

This release

0.0.20200813 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page