This module makes it simplely to run things in async.
Project description
async4s - 一个简单易用的异步执行模块
About
这是一个简单易用的异步执行模块,提供几个python装饰器,使原有方法轻松变为异步执行。
Requirements
- Python3
Install
通过pip命令安装:
pip install async4s
Example
- async by thread
import time
from async4s.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.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)
- Birth
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-1.0.0.zip
(21.8 kB
view details)
File details
Details for the file async4s-1.0.0.zip
.
File metadata
- Download URL: async4s-1.0.0.zip
- Upload date:
- Size: 21.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d037c634566b311efa23e189aab63b1ad821000793147aefe42e350998634a6a |
|
MD5 | 0a5131694f54e7003b688ccad200d524 |
|
BLAKE2b-256 | dc6702a02fdd017c89465d533e8db503e1af8950543a308c842eab7c00056dd9 |