Python异步工作者
aioworker的Python项目详细描述
工人
运行在asyncio
上的Python工作线程
要求
python 3.8+
安装
pip install aioworker
用法
^{pr2}$或者运行任务和Web服务器
importasynciofromaioworkerimportService,Workerasyncdefsleeping(loop):whileTrue:print('Sleeping for 2 seconds...')awaitasyncio.sleep(2)asyncdefon_client_connect(reader,writer):""" Read up tp 300 bytes of TCP. This could be parsed usign the HTTP protocol for example """data=awaitreader.read(300)print(f'TCP Server data received: {data}\n')writer.write(data)awaitwriter.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)
如何阻止工人
ctrl+c
默认值
Variable | Default |
---|---|
TCP server host | 0.0.0.0 |
TPC server port | 8888 |
示例
开发
- 克隆此回购
- 运行
poetry install
- 使用
./scripts/test
进行测试 - 使用
./scripts/lint
自动进行Lint
- 项目
标签: