fastapi-utils icon indicating copy to clipboard operation
fastapi-utils copied to clipboard

[BUG] Does not import on Windows

Open FaustinCarter opened this issue 4 years ago • 4 comments

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:

  1. 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

FaustinCarter avatar Dec 17 '20 21:12 FaustinCarter

work around is to run the fastapi app in docker.

don't know what is the equivalent package on windows side.

wasdee avatar Jan 09 '21 17:01 wasdee

Any update in this bug?

uncovor avatar Oct 29 '21 12:10 uncovor

any update?

menaitm avatar Jun 15 '22 09:06 menaitm

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)

rabigabor avatar Sep 02 '22 09:09 rabigabor