vpcarlos / profyle

Development tool for analysing and managing python traces
MIT License
115 stars 5 forks source link

PermissionError: [Errno 13] Permission denied: 'C:\\Users\\yotam\\AppData\\Local\\Temp\\tmpfk7tmhv0.json' #4

Open yotam201410 opened 3 months ago

yotam201410 commented 3 months ago

the example doesnt seem to work

import uvicorn
from fastapi import FastAPI
from profyle.fastapi import ProfyleMiddleware

app = FastAPI()
# Trace all requests that match that start with /users
# with a minimum duration of 100ms and a maximum stack depth of 20
app.add_middleware(
    ProfyleMiddleware,
    pattern="/users*",

)

@app.get("/users/{user_id}")
async def get_user(user_id: int):
    return {"hello": "user"}

uvicorn.run(app, host="127.0.0.1", port=8080)

i get the error mentioned in the title. your library seems really cool and i would really like to use it

vpcarlos commented 3 months ago

Thanks for reporting, I will take a look to this issue. Can you provide the entire error trace? Also I need more info about your operating system.

yotam201410 commented 3 months ago
INFO:     Started server process [21668]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8080 (Press CTRL+C to quit)
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python310\lib\site-packages\uvicorn\protocols\http\httptools_impl.py", line 399, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python310\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python310\lib\site-packages\fastapi\applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python310\lib\site-packages\starlette\applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python310\lib\site-packages\starlette\middleware\errors.py", line 186, in __call__
    raise exc
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python310\lib\site-packages\starlette\middleware\errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python310\lib\site-packages\profyle\infrastructure\middleware\fastapi.py", line 37, in __call__
    with profyle(
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python310\lib\site-packages\profyle\application\profyle.py", line 46, in __exit__
    self.tracer.save(temp_file.name)
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python310\lib\site-packages\viztracer\viztracer.py", line 235, in save
    rb.save(output_file=output_file, file_info=file_info)
  File "C:\Users\yotam\AppData\Local\Programs\Python\Python310\lib\site-packages\viztracer\report_builder.py", line 186, in save
    with open(output_file, "w", encoding="utf-8") as f:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\yotam\\AppData\\Local\\Temp\\tmp8i7s87zd.json'
mvanderlee commented 1 week ago

This is due to windows permissions, simply setting delete=False on the NamedTemporaryFile fixes it: https://github.com/vpcarlos/profyle/blob/main/profyle/application/profyle.py#L45

Relevant info: https://stackoverflow.com/questions/15588314/cant-access-temporary-files-created-with-tempfile