Skip to content

Commit

Permalink
Merge pull request #229 from tomchristie/run-in-threadpool
Browse files Browse the repository at this point in the history
Use Starlette's run_in_threadpool
  • Loading branch information
kennethreitz committed Nov 15, 2018
2 parents d94db41 + 69a300f commit 4001a60
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions responder/background.py
Expand Up @@ -3,6 +3,7 @@
import concurrent.futures
import multiprocessing
import traceback
from starlette.concurrency import run_in_threadpool


class BackgroundQueue:
Expand Down Expand Up @@ -40,6 +41,4 @@ async def __call__(self, func, *args, **kwargs) -> None:
if asyncio.iscoroutinefunction(func):
return await asyncio.ensure_future(func(*args, **kwargs))
else:
fn = functools.partial(func, *args, **kwargs)
loop = asyncio.get_event_loop()
return await loop.run_in_executor(None, fn)
return await run_in_threadpool(func, *args, **kwargs)
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -22,7 +22,7 @@
sys.exit()

required = [
"starlette",
"starlette<0.9",
"uvicorn",
"aiofiles",
"pyyaml",
Expand Down

0 comments on commit 4001a60

Please sign in to comment.