contextvars friendly ThreadPoolExecutor
Project description
- info:
contextvars friendly ThreadPoolExecutor
Installation
pip install contextvars_executor
Why???
Usage
import asyncio
import contextvars
from 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!!!
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
File details
Details for the file contextvars_executor-0.0.1.tar.gz
.
File metadata
- Download URL: contextvars_executor-0.0.1.tar.gz
- Upload date:
- Size: 2.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.2 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0a4+
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a47c1e8c29cbdb9006dae5d03be7fd329b5585fe8f0b62e0cd94eaf4db741bd |
|
MD5 | c00f01668a801500e77f325e093eee48 |
|
BLAKE2b-256 | 2ab7b465571636dfd2ae00f26a8647183e9d97ea2daca790347db5c27a4ec423 |