|buildstatus|_
|coverage|_
Asyncio background tasks
========================
Asyncio background tasks in Python 3.7 and later.
Run CPU intensive long running tasks without blocking the asyncio
loop, implemented as a lightweight asyncio layer on top of the
multiprocessing module.
Alternatively run tasks in other threads.
Project homepage: https://github.com/eerimoq/asyncbg
Documentation: https://asyncbg.readthedocs.org/en/latest
Installation
============
.. code-block:: python
pip install asyncbg
Examples
========
There are more examples in the `examples folder`_.
Call
----
Call ``work(a, b)`` in another process. The script output is ``Result: 9``.
.. code-block:: python
import asyncio
import asyncbg
def work(a, b):
return a + b
async def main():
result = await asyncbg.call(work, 4, 5)
print(f'Result: {result}')
asyncio.run(main())
Process pool
------------
Create a process pool with two workers, and call ``work()`` three
times in it (up to two callbacks called in parallel).
.. code-block:: python
import asyncio
import asyncbg
def work():
pass
async def main():
with asyncbg.ProcessPoolExecutor(max_workers=2) as pool:
await asyncio.gather(pool.call(work),
pool.call(work),
pool.call(work))
asyncio.run(main())
Call thread
-----------
Call ``work(a, b)`` in another thread. The script output is ``Result: 9``.
.. code-block:: python
import asyncio
import asyncbg
def work(a, b):
return a + b
async def main():
result = await asyncbg.call_thread(work, 4, 5)
print(f'Result: {result}')
asyncio.run(main())
Thread pool
-----------
Create a thread pool with two workers, and call ``work()`` three times
in it (up to two callbacks called in parallel).
.. code-block:: python
import asyncio
import asyncbg
def work():
pass
async def main():
with asyncbg.ThreadPoolExecutor(max_workers=2) as pool:
await asyncio.gather(pool.call(work),
pool.call(work),
pool.call(work))
asyncio.run(main())
.. |buildstatus| image:: https://travis-ci.org/eerimoq/asyncbg.svg?branch=master
.. _buildstatus: https://travis-ci.org/eerimoq/asyncbg
.. |coverage| image:: https://coveralls.io/repos/github/eerimoq/asyncbg/badge.svg?branch=master
.. _coverage: https://coveralls.io/github/eerimoq/asyncbg
.. _examples folder: https://github.com/eerimoq/asyncbg/tree/master/examples
Raw data
{
"_id": null,
"home_page": "https://github.com/eerimoq/asyncbg",
"name": "asyncbg",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "asyncio",
"author": "Erik Moqvist",
"author_email": "erik.moqvist@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/fe/c4/905e83237e0357fc86637a2099adddb75d34d4780166e82088e49e1295f6/asyncbg-0.12.0.tar.gz",
"platform": null,
"description": "|buildstatus|_\n|coverage|_\n\nAsyncio background tasks\n========================\n\nAsyncio background tasks in Python 3.7 and later.\n\nRun CPU intensive long running tasks without blocking the asyncio\nloop, implemented as a lightweight asyncio layer on top of the\nmultiprocessing module.\n\nAlternatively run tasks in other threads.\n\nProject homepage: https://github.com/eerimoq/asyncbg\n\nDocumentation: https://asyncbg.readthedocs.org/en/latest\n\nInstallation\n============\n\n.. code-block:: python\n\n pip install asyncbg\n\nExamples\n========\n\nThere are more examples in the `examples folder`_.\n\nCall\n----\n\nCall ``work(a, b)`` in another process. The script output is ``Result: 9``.\n\n.. code-block:: python\n\n import asyncio\n import asyncbg\n\n def work(a, b):\n return a + b\n\n async def main():\n result = await asyncbg.call(work, 4, 5)\n print(f'Result: {result}')\n\n asyncio.run(main())\n\nProcess pool\n------------\n\nCreate a process pool with two workers, and call ``work()`` three\ntimes in it (up to two callbacks called in parallel).\n\n.. code-block:: python\n\n import asyncio\n import asyncbg\n\n def work():\n pass\n\n async def main():\n with asyncbg.ProcessPoolExecutor(max_workers=2) as pool:\n await asyncio.gather(pool.call(work),\n pool.call(work),\n pool.call(work))\n\n asyncio.run(main())\n\nCall thread\n-----------\n\nCall ``work(a, b)`` in another thread. The script output is ``Result: 9``.\n\n.. code-block:: python\n\n import asyncio\n import asyncbg\n\n def work(a, b):\n return a + b\n\n async def main():\n result = await asyncbg.call_thread(work, 4, 5)\n print(f'Result: {result}')\n\n asyncio.run(main())\n\nThread pool\n-----------\n\nCreate a thread pool with two workers, and call ``work()`` three times\nin it (up to two callbacks called in parallel).\n\n.. code-block:: python\n\n import asyncio\n import asyncbg\n\n def work():\n pass\n\n async def main():\n with asyncbg.ThreadPoolExecutor(max_workers=2) as pool:\n await asyncio.gather(pool.call(work),\n pool.call(work),\n pool.call(work))\n\n asyncio.run(main())\n\n.. |buildstatus| image:: https://travis-ci.org/eerimoq/asyncbg.svg?branch=master\n.. _buildstatus: https://travis-ci.org/eerimoq/asyncbg\n\n.. |coverage| image:: https://coveralls.io/repos/github/eerimoq/asyncbg/badge.svg?branch=master\n.. _coverage: https://coveralls.io/github/eerimoq/asyncbg\n\n.. _examples folder: https://github.com/eerimoq/asyncbg/tree/master/examples\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Asyncio background tasks.",
"version": "0.12.0",
"split_keywords": [
"asyncio"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8935dcac913f52ca4da452f3c15b2095da2745deff832c568eb9fc06305f94d6",
"md5": "abc200738904c66dfa3de987db249fbb",
"sha256": "12bc0046830a52b50a67a98a927c1dd36c2aea978baf0cda2d556eae39cfcb39"
},
"downloads": -1,
"filename": "asyncbg-0.12.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "abc200738904c66dfa3de987db249fbb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 3560,
"upload_time": "2023-04-19T18:54:37",
"upload_time_iso_8601": "2023-04-19T18:54:37.527709Z",
"url": "https://files.pythonhosted.org/packages/89/35/dcac913f52ca4da452f3c15b2095da2745deff832c568eb9fc06305f94d6/asyncbg-0.12.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "fec4905e83237e0357fc86637a2099adddb75d34d4780166e82088e49e1295f6",
"md5": "50848321cdee9e65b60150e46f82e084",
"sha256": "b8dc556953f829e4b2c31307cd7480273ef88322468dc1ef0c7d1c292bf056fc"
},
"downloads": -1,
"filename": "asyncbg-0.12.0.tar.gz",
"has_sig": false,
"md5_digest": "50848321cdee9e65b60150e46f82e084",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3862,
"upload_time": "2023-04-19T18:54:38",
"upload_time_iso_8601": "2023-04-19T18:54:38.897132Z",
"url": "https://files.pythonhosted.org/packages/fe/c4/905e83237e0357fc86637a2099adddb75d34d4780166e82088e49e1295f6/asyncbg-0.12.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-19 18:54:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "eerimoq",
"github_project": "asyncbg",
"travis_ci": true,
"coveralls": true,
"github_actions": true,
"requirements": [],
"lcname": "asyncbg"
}