Skip to main content

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 语法


版本 | Documentation Status | GitHub release (latest by date)

consign 可以使函数得以以协程的方式运行,以更低的代码侵入性,获得更高的效率

快速开始

consign 几乎没有需要安装的依赖,在GitHub中开箱即用即可

更多信息请查看 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyconsign-1.0.2.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

pyconsign-1.0.2-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

Details for the file pyconsign-1.0.2.tar.gz.

File metadata

  • Download URL: pyconsign-1.0.2.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.20.1 requests-toolbelt/0.10.0 urllib3/1.26.12 tqdm/4.41.0 importlib-metadata/4.8.0 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.4

File hashes

Hashes for pyconsign-1.0.2.tar.gz
Algorithm Hash digest
SHA256 b1dcce238a85e06470812a274c5e322998d95be699e7f0aa67d818fc119983dc
MD5 6e6ae1edc4c49a2bed2fa51970c3529f
BLAKE2b-256 63917e1c8008802aa79d03d01dcd94c885427827638702b977f3e538b5c61ff1

See more details on using hashes here.

File details

Details for the file pyconsign-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyconsign-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 26.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.20.1 requests-toolbelt/0.10.0 urllib3/1.26.12 tqdm/4.41.0 importlib-metadata/4.8.0 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.4

File hashes

Hashes for pyconsign-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 46e8381eec353bc2c51fdb466951000c7b7dbda528684ce1018d3933a2060fa4
MD5 26f764bce408d7f9cb3c6dd2c37d36ed
BLAKE2b-256 067539aa83948679d08c6bbea7620306dc8c572fbe2b882e3896668197f0e6a6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page