Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hellysmile/contextvars_executor
contextvars friendly ThreadPoolExecutor
https://github.com/hellysmile/contextvars_executor
asyncio contextvars
Last synced: 29 days ago
JSON representation
contextvars friendly ThreadPoolExecutor
- Host: GitHub
- URL: https://github.com/hellysmile/contextvars_executor
- Owner: hellysmile
- Created: 2018-09-21T23:18:14.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-10-30T02:54:20.000Z (2 months ago)
- Last Synced: 2024-12-01T02:35:19.464Z (about 1 month ago)
- Topics: asyncio, contextvars
- Language: Python
- Homepage: https://pypi.org/project/contextvars-executor/
- Size: 25.4 KB
- Stars: 15
- Watchers: 3
- Forks: 1
- Open Issues: 10
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
contextvars_executor
====================:info: contextvars friendly ThreadPoolExecutor
.. image:: https://travis-ci.org/hellysmile/contextvars_executor.svg?branch=master
:target: https://travis-ci.org/hellysmile/contextvars_executor.. image:: https://img.shields.io/pypi/v/contextvars_executor.svg
:target: https://pypi.python.org/pypi/contextvars_executor.. image:: https://codecov.io/gh/hellysmile/contextvars_executor/branch/master/graph/badge.svg
:target: https://codecov.io/gh/hellysmile/contextvars_executorInstallation
------------.. code-block:: shell
pip install contextvars_executor
Why???
------* `related Python issue `_
Usage
-----.. code-block:: python
import asyncio
import contextvarsfrom contextvars_executor import ContextVarExecutor
ctx = contextvars.ContextVar('42')
def thread():
ret = ctx.get()assert ret == 42
return ret
async def main(*, loop):
ctx.set(42)ret = await loop.run_in_executor(None, thread)
assert ret == 42
loop = asyncio.get_event_loop()
loop.set_default_executor(ContextVarExecutor())
loop.run_until_complete(main(loop=loop))Python 3.7+ is required, there is no need to support older python versions!!!