[Python] Python debugging in vscode ends after 5 seconds of inactivity

Discussão em 'Python' iniciado por Stack, Novembro 25, 2024.

  1. Stack

    Stack Membro Participativo

    I'm on Macbook Pro M4 Max, python 3.9.20 running in conda environment. I'm using vscode to debug the program, but when debugging, the child process dies after 5 seconds of not doing anything (a breakpoint lasts 5 seconds only): my python program is launched using a script launch_proxy.py which launches a uvicorn instance serving my api.

    import uvicorn
    if __name__ == "__main__":
    workers = 6
    uvicorn.run("api.detection_proxy:app", host="0.0.0.0", port=8184,workers=workers, reload=workers == 1, proxy_headers=True, forwarded_allow_ips="*")


    and a launch.json in vscode:

    {
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
    {
    "name": "Python: Current File",
    "type": "debugpy",
    "stopOnEntry": false,
    "request": "launch",
    "program": "launch_proxy.py",
    "console": "integratedTerminal",
    "justMyCode": false,
    "cwd": "${workspaceFolder}/ppl_server",
    "env": {
    "DYLD_LIBRARY_PATH": "/opt/homebrew/lib/postgresql@14/:$DYLD_LIBRARY_PATH",
    "PYDEVD_USE_FRAME_EVAL": "NO",
    "PYDEVD_TIMEOUT": "999999",
    "PYDEVD_DEBUG_LOG_DIR": "/tmp/debugpy_logs"
    },
    }
    ]
    }


    The program runs fine But when it hits a breakpoint, if you don't do a step over or a step into within 5 seconds of reaching this breakpoint, the child process dies, and is restarted leaving me with an empty response, and no debugging whatsoever

    As my launch.json suggests, I have tried many parameters and configs to circumvent the 5 seconds, I even tried listening for any signal in the launch_proxy.py file like this:

    import signal
    import sys

    def signal_handler(sig, frame):
    print(f"Received signal: {sig}")
    sys.exit(0)

    signal.signal(signal.SIGTERM, signal_handler)
    signal.signal(signal.SIGINT, signal_handler)

    #this part is to print something that's how i knew a new child process has spawned
    import os
    print("PYDEVD_TIMEOUT:", os.environ.get("PYDEVD_TIMEOUT"))
    print("PYDEVD_USE_FRAME_EVAL:", os.environ.get("PYDEVD_USE_FRAME_EVAL"))
    print("DYLD_LIBRARY_PATH:", os.environ.get("DYLD_LIBRARY_PATH"))


    The signal handler prints nothing when the child process dies I tested the signal handler by issuing a ctrl + c, and i can see it prints signal 15 received

    I should mention that a similar setup with the same versions of the pip packages works fine on my windows laptop

    Continue reading...

Compartilhe esta Página