Skip to main content

No project description provided

Project description

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 spawn_monitored, receive, reply, send, run

async def ping_pong():
    while True:
        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_monitored(ping_pong())

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

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

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


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

TODO:

Lot of things!

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

aioerl-0.0.20190425.3.tar.gz (16.9 kB view details)

Uploaded Source

File details

Details for the file aioerl-0.0.20190425.3.tar.gz.

File metadata

  • Download URL: aioerl-0.0.20190425.3.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for aioerl-0.0.20190425.3.tar.gz
Algorithm Hash digest
SHA256 663acdf4e1820431bfd0f6eb9b324ed03abc29134c156d891ce1b713a4a637b8
MD5 0514646e4b16c18f5c04dba16ce24995
BLAKE2b-256 edec1c9c31a5abcb3c0b8acfa791772f152ea5557db65be179b87d8f6e28790b

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