Skip to content

Commit

Permalink
some fixes in pool
Browse files Browse the repository at this point in the history
  • Loading branch information
rking32 committed Jun 30, 2020
1 parent 7bd12f8 commit ec1e05c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions userge/core/ext/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import asyncio
from typing import Any, Callable, Optional, Union, Iterable, Iterator
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor, Future
from functools import wraps
from functools import wraps, partial

_THREAD_POOL = ThreadPoolExecutor(4)
_PROCESS_POOL = ProcessPoolExecutor(4)
Expand Down Expand Up @@ -48,13 +48,13 @@ def map_processes(func: Callable[[Any], Any],
def run_in_thread(func: Callable[[Any], Any]) -> Callable[[Any], Any]:
""" run in a thread """
@wraps(func)
async def wrapper(*args: Any) -> Any:
async def wrapper(*args: Any, **kwargs: Any) -> Any:
loop = asyncio.get_running_loop()
return await loop.run_in_executor(_THREAD_POOL, func, *args)
return await loop.run_in_executor(_THREAD_POOL, partial(func, *args, **kwargs))
return wrapper


async def run_in_process(func: Callable[[Any], Any], *args: Any) -> Any:
async def run_in_process(func: Callable[[Any], Any], *args: Any, **kwargs: Any) -> Any:
""" run in a process """
loop = asyncio.get_running_loop()
return await loop.run_in_executor(_PROCESS_POOL, func, *args)
return await loop.run_in_executor(_PROCESS_POOL, partial(func, *args, **kwargs))

0 comments on commit ec1e05c

Please sign in to comment.