Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3.12 Unable to attach to PID (Jupyter python process) #1476

Closed
fleming79 opened this issue Dec 4, 2023 · 15 comments
Closed

Python3.12 Unable to attach to PID (Jupyter python process) #1476

fleming79 opened this issue Dec 4, 2023 · 15 comments
Labels
bug Something isn't working

Comments

@fleming79
Copy link

With VScode I normally debug IpyWidgets by attaching to a Jupyter Kenrnel using PID. With python 3.11 this works with an external Jupyter kernel or one managed by VScode.

Switching to using Python 3.12 it no longer connects to the PID. The only indication is a message in the console Python:....

Attaching to PID: 19800 (elapsed: 1.00s).
Attaching to PID: 19800 (elapsed: 2.00s).

Stops counting at 2.00s.

With Python 3.11 it counts up to about 8s then connects.

Environment data

  • debugpy version: 1.8.0
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): 3.12 WinPython distribution
  • Using VS Code:
    Version: 1.84.2
    Commit: 1a5daa3a0231a0fbba4f14db7ec463cf99d7768e
    Date: 2023-11-09T10:51:52.184Z
    Electron: 25.9.2
    ElectronBuildId: 24603566
    Chromium: 114.0.5735.289
    Node.js: 18.15.0
    V8: 11.4.183.29-electron.0
    OS: Windows_NT x64 10.0.19045

Actual behavior

  • Debugger doesn't attach (Timeout error).

Expected behavior

  • Debugger attaches to PID after about 8s.

Steps to reproduce:

  1. Start VScode.
  2. Start Jupyter and obtain PID for a Python 3.12 kernel.
  3. Attach to PID using Python debugger.

Launch settings

    {
        "name": "Python: Attach using Process Id",
        "type": "python",
        "request": "attach",
        "processId": "${command:pickProcess}",
        "subProcess": false
    }
@int19h
Copy link
Contributor

int19h commented Dec 4, 2023

Could you enable logs using "logToFile": true in your launch.json, and share debugpy.server*.log?

@int19h int19h added the bug Something isn't working label Dec 4, 2023
@fleming79
Copy link
Author

fleming79 commented Dec 4, 2023

Unfortunately I don't see a debugpy.server*.log file.

These may be relevant.

debugger.vscode_24ababd2-a99b-44d7-a395-aea0bf4197c5.log
debugpy.adapter-15968.log

For my ref: how to find log file

@int19h
Copy link
Contributor

int19h commented Dec 4, 2023

Indeed, my apologies; the "logToFile" setting wouldn't be applied in this case. Instead, set the DEBUGPY_LOG_DIR environment variable for the process you're attaching to point at the directory where it should place the logs.

@fleming79
Copy link
Author

Thank you for the guidance.
debugpy.server-21680.log

@int19h
Copy link
Contributor

int19h commented Dec 4, 2023

Hm, was there only one server log generated? Normally there should be two in this scenario - the one above is from the process that performs the injection, but the second one should be from bits of the debugger that get injected.

@fleming79
Copy link
Author

fleming79 commented Dec 4, 2023

There were two files created at the same time.

Python 3.12 kernel.

debugpy.server-6620.log
debugpy.pydevd.6620.log

Python 3.11 kernel.

Similar log files (with same prefix) are generated when successfully connecting.
debugpy.server-19904.log
debugpy.pydevd.19904.log

@fleming79
Copy link
Author

fleming79 commented Dec 7, 2023

I switched to using a system environment variable instead of using WinPython to add the variable and now get three files:

debugpy.adapter-4172.log
debugpy.pydevd.6836.log
debugpy.server-6836.log

@fleming79
Copy link
Author

As another hint, the console in which Jupyter is running emits the following message:

Python version unknown!
Error when injecting code in target process. Error code (on windows): 5

@omasoud
Copy link

omasoud commented Feb 2, 2024

I ran into the same error. Tried with the process being just python.exe too; same thing.

Python version unknown!
Error when injecting code in target process. Error code (on windows): 5

debugpy.adapter-22480.log
debugger.vscode_236ca7a3-324e-4f22-870f-7f2842027d18.log

I'm guessing it's ending up here.

@tonyroberts
Copy link

Seems like Python 3.12 isn't supported at the moment? GetPythonVersion returns PythonVersion_Unknown for Python 3.12

return PythonVersion_Unknown; // we don't care about 3.1 anymore...

@NitroTamagotschi
Copy link

I ran into the same error by using a simple Python script instead of a jupyter notebook.

@xuweiwang2021
Copy link

Any solution for this issue? I got the same error in Anaconda Prompt running python 3.12 when debug in VS Code by attach using Process Id.
conda 24.3.0
python 3.12.2, python 3.12.3
VS Code 1.89.0
Python version unknown!
Error when injecting code in target process. Error code (on windows): 5

@AdamYoblick
Copy link
Member

Yeah this is a known issue. Attach to a python 3.12 process doesn't work yet because of all the internal changes in 3.12 that we haven't caught up with. In the meantime, 3.11 should work.

@xuweiwang2021
Copy link

xuweiwang2021 commented May 8, 2024 via email

@rchiodo
Copy link
Contributor

rchiodo commented Sep 24, 2024

This issue should be fixed in the latest build of debugpy. It should ship with VS code in a future version of the Python Debugger Extension or you can install your own debugpy from pypi

@rchiodo rchiodo closed this as completed Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants