https://github.com/masipcat/aioerl
a python library that mimics the philosophy of Erlang's processes with asyncio tasks
https://github.com/masipcat/aioerl
asyncio
Last synced: about 2 months ago
JSON representation
a python library that mimics the philosophy of Erlang's processes with asyncio tasks
- Host: GitHub
- URL: https://github.com/masipcat/aioerl
- Owner: masipcat
- License: gpl-3.0
- Created: 2019-04-24T23:18:46.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-19T13:10:16.000Z (almost 5 years ago)
- Last Synced: 2025-04-11T18:57:20.027Z (about 2 months ago)
- Topics: asyncio
- Language: Python
- Homepage:
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# aioerl
[](https://badge.fury.io/py/aioerl)
`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](##example)).
## Quickstart
Requirements: Python 3.7+
Installation:
```bash
pip install aioerl
```## Example
```python
from aioerl import receive
from aioerl import reply
from aioerl import send
from aioerl import spawnimport 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 processasync def main():
p = await spawn(ping_pong())await send(p, "ping")
print(await receive()) # Message(sender=, event='ok', body='pong')await send(p, "pang")
print(await receive()) # Message(sender=, event='err', body=Exception('Invalid message body'))await send(p, "ping")
print(await receive()) # Message(sender=, event='exit', body='noproc')if __name__ == "__main__":
asyncio.run(main())
```## TODO:
Lot of things!