aioworker
A Python worker running over asyncio
Requirements
python 3.8+
Installation
pip install aioworker
Usage
import asyncio
from aioworker import Service, Worker
async def task_1(loop):
while True:
print('Hello world')
await asyncio.sleep(2)
if __name__ == '__main__':
# Run the server using 1 worker processes.
Worker(tasks=[task_1]).run(workers=1)
or run tasks and the webserver
import asyncio
from aioworker import Service, Worker
async def sleeping(loop):
while True:
print('Sleeping for 2 seconds...')
await asyncio.sleep(2)
async def on_client_connect(reader, writer):
"""
Read up tp 300 bytes of TCP. This could be parsed usign the HTTP protocol for example
"""
data = await reader.read(300)
print(f'TCP Server data received: {data} \n')
writer.write(data)
await writer.drain()
writer.close()
if __name__ == '__main__':
# Run the server using 1 worker processes.
Worker(
tasks=[sleeping],
web_server_config={
'client_connected_cb': on_client_connect,
},
)).run(workers=1)
How to stop the worker
ctrl+c
Default values
| Variable | Default |
|---|---|
| TCP server host | 0.0.0.0 |
| TPC server port | 8888 |
Examples
Development
- Clone this repo
- Run
poetry install - Test using
./scripts/test - Lint automatically using
./scripts/lint
Release files for aioworker 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aioworker-0.2.0.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aioworker-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.9 kB
Release files / aioworker-0.2.0.tar.gz
| Download URL | aioworker-0.2.0.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9e6a3bba7b2c0cc93901f844fba8253a0e7f7e375c3721edbf64d6377f1977b
|
|
BLAKE2b-256 checksum How to use checksums |
f0fa0d4c245e61ddcd970de34cbfed6ca7153d691160b66b1d83b2ce7e8d8e8c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.2 CPython/3.8.1 Darwin/17.7.0
|
Release files / aioworker-0.2.0-py3-none-any.whl
| Download URL | aioworker-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
57e39360366b437f7f1caefc07691cec33d14e2051d12b81527fb22c9abd3b25
|
|
BLAKE2b-256 checksum How to use checksums |
6ab8b071746f4fa4fc8b587605e773bbb87b1e1b61f3796a231e80e55d87e624
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.2 CPython/3.8.1 Darwin/17.7.0
|