Skip to content

Instantly share code, notes, and snippets.

@giladbarnea
Last active March 23, 2025 16:30
Show Gist options
  • Select an option

  • Save giladbarnea/86fd3f401e3b28b1028112a8935c2d50 to your computer and use it in GitHub Desktop.

Select an option

Save giladbarnea/86fd3f401e3b28b1028112a8935c2d50 to your computer and use it in GitHub Desktop.
asyncio threadiing multiprocessing and concurrency snippets
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