Skip to content

Commit 976b8f3

Browse files
committed
async: add run_in_executor helper
1 parent a9c01e4 commit 976b8f3

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

enapter/async_/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from .generator import generator
22
from .routine import Routine
3+
from .run_in_executor import run_in_executor
34

45
__all__ = [
56
"generator",
67
"Routine",
8+
"run_in_executor",
79
]

enapter/async_/run_in_executor.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import asyncio
2+
import functools
3+
4+
5+
async def run_in_executor(func, *args, **kwargs):
6+
loop = asyncio.get_running_loop()
7+
return await loop.run_in_executor(None, functools.partial(func, *args, **kwargs))

0 commit comments

Comments
 (0)