fastapi-utils
fastapi-utils copied to clipboard
[BUG] Does not import on Windows
Describe the bug
Fails completely on Windows because resource
is not available on Windows.
\lib\site-packages\fastapi_utils\timing.py", line 10, in <module> import resource
ModuleNotFoundError: No module named 'resource'
To Reproduce Steps to reproduce the behavior:
-
pip install fastapi-utils
2.from fastapi_utils.timing import add_timing_middleware
Expected behavior The import works.
Environment:
- OS: Windows 10
- Python version: 3.7
Additional context https://stackoverflow.com/questions/37710848/importerror-no-module-named-resource
work around is to run the fastapi app in docker.
don't know what is the equivalent package on windows side.
Any update in this bug?
any update?
In the timing.py, you can use this code snippet instead, it gives you almost the same result:
def _get_cpu_time() -> float:
"""
Generates the cpu time to report. Adds the user and system time, following the implementation from timing-asgi
"""
return time.process_time()
(Python 3.3+ needed)