Python async worker
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aioworker-0.2.0.tar.gz
(4.5 kB
view details)
Built Distribution
File details
Details for the file aioworker-0.2.0.tar.gz
.
File metadata
- Download URL: aioworker-0.2.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.2 CPython/3.8.1 Darwin/17.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9e6a3bba7b2c0cc93901f844fba8253a0e7f7e375c3721edbf64d6377f1977b |
|
MD5 | 3fd6035c056a5142191d617d2c30bd11 |
|
BLAKE2b-256 | f0fa0d4c245e61ddcd970de34cbfed6ca7153d691160b66b1d83b2ce7e8d8e8c |
File details
Details for the file aioworker-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: aioworker-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.2 CPython/3.8.1 Darwin/17.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57e39360366b437f7f1caefc07691cec33d14e2051d12b81527fb22c9abd3b25 |
|
MD5 | 331238cdc1c05d4667cdc328cbfe3913 |
|
BLAKE2b-256 | 6ab8b071746f4fa4fc8b587605e773bbb87b1e1b61f3796a231e80e55d87e624 |