Generator-based Coroutines, Easy to use, Using the yield syntax
Project description
Consign
Generator-based Coroutines, Easy to use, Using the yield syntax
consign 是基于 generator 的协程框架,易于使用,使用 yield 语法
consign 可以使函数得以以协程的方式运行,以更低的代码侵入性,获得更高的效率
快速开始
python>=3.7:consign 几乎没有需要安装的依赖
反之会需要安装 contextvars,仅此而已
你可以通过 pip 快速安装:
pip install pyconsign
或者通过 git 开箱即用
python setup.py install
更多信息请查看 consign's documentation
简单例子
初探特性
>>> from consign import coroutine, asleep, CoroutineWorker
>>> import threading
>>> @coroutine
... def my_test(name: str):
... print(f"{name} start in {threading.currentThread()}")
... result = yield asleep(3)
... print(f"{name} end in {threading.currentThread()} result is {result}")
... return name
...
>>> test_task1, test_task2 = my_test("task1"), my_test("task2")
>>> test_task1
{
'task_state': <TaskState.NoStart: 'NoStart'>,
'value': <TaskResult.NoGet: 'NoGet'>,
'work_area': <'DEFAULT_WORK_AREA' Work at 0x25940db46a0 and in <_MainThread(MainThread, started 31352)>>,
'order': {
'consignor_func': <function my_test at 0x000002593EEF2EA0>,
'create_area': <'DEFAULT_WORK_AREA' Work at 0x25940db46a0 and in <_MainThread(MainThread, started 31352)>>,
'create_callback': None,
'complete_callback': None
}
}
>>> CoroutineWorker().loop_work(forever=False)
task1 start in <_MainThread(MainThread, started 24332)>
task2 start in <_MainThread(MainThread, started 24332)>
task1 end in <_MainThread(MainThread, started 24332)> result is None
task2 end in <_MainThread(MainThread, started 24332)> result is None
>>> test_task1
{
'task_state': <TaskState.TaskDone: 'TaskDone'>,
'value': 'task1',
'work_area': <'DEFAULT_WORK_AREA' Work at 0x23fbe9f46d8 and in <_MainThread(MainThread, started 24332)>>,
'order': {
'consignor_func': <function my_test at 0x0000023FBCB42EA0>,
'create_area': <'DEFAULT_WORK_AREA' Work at 0x23fbe9f46d8 and in <_MainThread(MainThread, started 24332)>>,
'create_callback': None,
'complete_callback': None
}
}
更多还在路上...
License
This project is licensed under the MIT License. 享受开源
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyconsign-1.0.3.tar.gz.
File metadata
- Download URL: pyconsign-1.0.3.tar.gz
- Upload date:
- Size: 21.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb34d1a86c5545f1d89324ee4efe1727849995f890538422d3e54ec868a2551f
|
|
| MD5 |
73457ebc7d373fa71a389b5ff6593096
|
|
| BLAKE2b-256 |
8107aa39ac21b3b10d427187636ef2de4354dd1e4c2fa4a002779aa4429396aa
|
File details
Details for the file pyconsign-1.0.3-py3-none-any.whl.
File metadata
- Download URL: pyconsign-1.0.3-py3-none-any.whl
- Upload date:
- Size: 26.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75b4be5f2fadcdda4ab98d6d74cfe94e996c4a3492d6bd2d1eb52c773b099bde
|
|
| MD5 |
7b41efa1d2e98302a8ff57eeffe90f64
|
|
| BLAKE2b-256 |
9fed1de9d063bdf49686eb3c161b32b7b7fec9b851e9aa25760f997ff09feed6
|