Merge pull request #229 from tomchristie/run-in-threadpool

Use Starlette's run_in_threadpool
This commit is contained in:
2018-11-15 06:24:34 -05:00
committed by GitHub
2 changed files with 3 additions and 4 deletions
+2 -3
View File
@@ -3,6 +3,7 @@ import functools
import concurrent.futures
import multiprocessing
import traceback
from starlette.concurrency import run_in_threadpool
class BackgroundQueue:
@@ -40,6 +41,4 @@ class BackgroundQueue:
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)
+1 -1
View File
@@ -22,7 +22,7 @@ if sys.argv[-1] == "publish":
sys.exit()
required = [
"starlette",
"starlette<0.9",
"uvicorn",
"aiofiles",
"pyyaml",