PTVS
PTVS copied to clipboard
Subprocess with visual studio debugger attached to process causes a problem in python project
This issue has been moved from a ticket on Developer Community.
I'm facing a very annoying issue with Visual Studio 2022. Here's how to replicate it.
Folder contents:
test-debugpy-issue
| test-debugpy-issue.sln
|
\---test-debugpy-issue
cli.py
environment.json
test-debugpy-issue.pyproj
test_debugpy_issue.py
test_debugpy_issue_simplified.py
Contents of cli.py
:
print("hello world")
Contents of test_debugpy_issue_simplified
:
import subprocess
import os
import json
print(os.getpid())
input()
configArgs = ["python", "cli.py"]
ret_code=0
while ret_code==0:
ret_code = subprocess.call(configArgs, shell=False, universal_newlines=True)
print(ret_code)
In order to replicate the issue, carry out the following steps:
- Open up a Powershell or CMD terminal
- Run
python .\test_debugpy_issue.py
- Copy the provided PID
- In Visual Studio 2022 under Debug > Attach to Process, paste the PID, select the process as shown below:
[! [enter image description here] 1] 1
- Click Attach, then wait in the Output window until the process has successfully attached. This apparently requires multiple attempts:
[! [enter image description here] 2] 2
- Go back into your Powershell and CMD terminal and press Enter
- The following error should appear:
0.47s - Error importing debugpy._vendored.force_pydevd (with sys.path entry: 'c:\program > files\microsoft visual studio\2022\professional\common7\ide\extensions\microsoft\python\core') Traceback (most recent call last): File "c:\program files\microsoft visual studio\2022\professional\common7\ide\extensions\microsoft\python\core\debugpy_vendored\pyde> vd_pydevd_bundle\pydevd_defaults.py", line 60, in on_pydb_init import(module_name) ModuleNotFoundError: No module named 'debugpy'
I've found this issue on Github which describes a similar problem, but it's from the Vs Code repo. I'm not using VS Code.
Why is this happening and how can I fix it ?
Original Comments
Feedback Bot on 4/7/2023, 01:36 AM:
(private comment, text removed)
Original Solutions
(no solutions)
@int19h Could you help taking a look at this one whenever you got a chance? Thanks.😊
@StellaHuang95 thanks, I had also logged a similar issue for VS Code so that might be related, since I think both IDE's use debugpy
.