-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update fastapi version, add run_in_processpool api
- Loading branch information
Showing
4 changed files
with
79 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
Concurrency module | ||
""" | ||
import asyncio | ||
from concurrent.futures import ProcessPoolExecutor | ||
import functools | ||
import typing | ||
from application import logger | ||
import pprint | ||
|
||
LOGGER = logger.get_application_logger() | ||
|
||
T = typing.TypeVar('T') | ||
|
||
PROCESS_POOL_EXECUTOR = ProcessPoolExecutor() | ||
|
||
|
||
async def run_in_processpool(func: typing.Callable[..., T], | ||
*args: typing.Any, | ||
**kwargs: typing.Any) -> T: | ||
""" | ||
run in process pool executor | ||
:param func: function | ||
:param args: args | ||
:param kwargs: keyword args | ||
:return: | ||
""" | ||
LOGGER.debug('Run in processpool with func: %s, args: %s, kwargs: %s' % | ||
(pprint.pformat(func), pprint.pformat(args), pprint.pformat(kwargs))) | ||
loop = asyncio.get_event_loop() | ||
f = functools.partial(func, **kwargs) | ||
return await loop.run_in_executor(None, f, *args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
atomicwrites==1.4.0 | ||
attrs==19.3.0 | ||
certifi==2020.6.20 | ||
attrs==20.3.0 | ||
certifi==2020.12.5 | ||
chardet==3.0.4 | ||
click==7.1.2 | ||
colorama==0.4.3 | ||
fastapi==0.61.1 | ||
h11==0.9.0 | ||
colorama==0.4.4 | ||
fastapi==0.62.0 | ||
h11==0.11.0 | ||
idna==2.10 | ||
more-itertools==8.4.0 | ||
packaging==20.4 | ||
iniconfig==1.0.1 | ||
more-itertools==8.6.0 | ||
packaging==20.7 | ||
pluggy==0.13.1 | ||
py==1.9.0 | ||
pydantic==1.6.1 | ||
pydantic==1.7.3 | ||
pyparsing==2.4.7 | ||
pytest==6.1.1 | ||
python-dotenv==0.14.0 | ||
pytest==6.1.2 | ||
python-dotenv==0.15.0 | ||
python-multipart==0.0.5 | ||
requests==2.24.0 | ||
requests==2.25.0 | ||
six==1.15.0 | ||
starlette==0.13.6 | ||
urllib3==1.25.10 | ||
uvicorn==0.11.8 | ||
toml==0.10.1 | ||
urllib3==1.26.2 | ||
uvicorn==0.12.3 | ||
wcwidth==0.2.5 | ||
websockets==8.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters