This module makes it simplely to run things in async.
Project description
async4s - 一个简单易用的异步执行模块
About
这是一个简单易用的异步执行模块,可以使原有方法轻松变为异步执行。
Requirements
- Python3
Install
通过pip命令安装:
pip install async4s
Example
- async by thread
import time
from async4s.mw.thread import Master, Worker
def work(i):
time.sleep(i)
return i
def callback(results):
print(results)
print(time.perf_counter())
workers = [Worker(work, i) for i in range(5)]
m = Master(workers, callback)
print("main")
m.wait()
print(time.perf_counter())
- async by asyncio
import time
import asyncio
from async4s.mw.coroutine import Master, Worker
async def work(i):
await asyncio.sleep(i)
return i
def callback(results):
print(results)
print(time.perf_counter())
workders = (Worker(work, i) for i in range(5))
master = Master(workders, callback=callback)
print("main")
master.wait()
print(time.perf_counter())
Release History
0.0.1(2021-01-26)
- Birth
1.0.0(2021-10-29)
- Master-Worker mode
- both implement by thread and asyncio
Author
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
async4s-2.3.2.zip
(13.4 kB
view details)
File details
Details for the file async4s-2.3.2.zip
.
File metadata
- Download URL: async4s-2.3.2.zip
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df3f6e09e05913c50d7b99c04fc450c2fad5c934a27d66d2e07f323e83d535c5 |
|
MD5 | 3f9250047b06e23831ac240254f78f75 |
|
BLAKE2b-256 | 7d46afffc1fae04e4e2efc050489666163cf91ac63d90a9421e7ca21e76469ee |