Last active
March 23, 2025 16:30
-
-
Save giladbarnea/86fd3f401e3b28b1028112a8935c2d50 to your computer and use it in GitHub Desktop.
asyncio threadiing multiprocessing and concurrency snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| from functools import partial | |
| from typing import Callable, TypeVar, ParamSpec | |
| P = ParamSpec("P") | |
| R = TypeVar("R") | |
| loop = asyncio.get_event_loop() | |
| async def asyncify(func: Callable[P, R], *args: P.args, **kwargs: P.kwargs) -> R: | |
| return await loop.run_in_executor(loop, partial(func, **kwargs), *args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment