Not able to attach to a sub process #1698
Unanswered
JeevananthamSathish
asked this question in
Q&A
Replies: 3 comments 4 replies
-
Can you share some example code? I can try it myself. Reading about Pythonnet it sounds like it should work, but there might be something that pythonnet is doing that messes up attach. There's also a |
Beta Was this translation helpful? Give feedback.
0 replies
-
HI Rich Chiodo,
*
Thanks for taking time to respond my query
*
I actually found the issue and resolved it.
*
I had path mappings which was causing the issue i removed it - then it worked like a magic
*
But i had to call configure method before calling listen - in python script otherwise not attaching.
Python Script
debugpy.configure(subprocess=False)
debugpy.listen(5678)
debugpy.wait_for_client() # This will pause the execution until a debugger attaches
debugpy.breakpoint()
config json:
"configurations": [
{
"name": "Python Debugger: Remote Attach",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"justMyCode": false
}
]
My Pythonnet c# code :
PythonEngine.PythonHome = @"C:\Users\SATHISHKUMAR\AppData\Local\Programs\Python\Python39";
// Add the Python standard library to Python path
PythonEngine.PythonPath = Environment.GetEnvironmentVariable("PYTHONPATH") + ";" +
@"C:\Users\SATHISHKUMAR\AppData\Local\Programs\Python\Python39\Lib";
PythonEngine.DebugGIL = true;
PythonEngine.Initialize();
try
{
string pythonScriptPath = "D:\\debugTestPython\\script.py";
if (File.Exists(pythonScriptPath))
{
string script = File.ReadAllText(pythonScriptPath);
using (Py.GIL()) // Ensures proper handling of Python Global Interpreter Lock (GIL)
{
// Execute the Python code
PythonEngine.Exec(script);
}
}
else
{
Console.WriteLine($"File {pythonScriptPath} not found.");
}
//PythonEngine.Shutdown();
}
*
Now i can able to attach but whenever i inspect a variable the tool crashes. Any solution.?
*
Anything wrong in my configuration or script - kindly share your suggestions to improve.
Regards
Sathishkumar Jeevanantham
…________________________________
From: Rich Chiodo ***@***.***>
Sent: 14 October 2024 09:34 PM
To: microsoft/debugpy ***@***.***>
Cc: JeevananthamSathish ***@***.***>; Author ***@***.***>
Subject: Re: [microsoft/debugpy] Not able to attach to a sub process (Discussion #1698)
Can you share some example code? I can try it myself.
Reading about Pythonnet<https://pythonnet.github.io/> it sounds like it should work, but there might be something that pythonnet is doing that messes up attach.
There's also a logToFile setting you can set in VS code's launch.json. This will output a bunch of log files in your \ms-python.debugpy- folder.
—
Reply to this email directly, view it on GitHub<#1698 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BFKDN7VJUDVKLCMY6MFVAM3Z3PTQBAVCNFSM6AAAAABP2PO2DKVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTAOJTHA3TONI>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
2 replies
-
Forget to mention :
*
Whenever the debugg adapter attaches it opened a new tab in vscode with title <string> :
*
To solve this -> i added a environment variable PATHS_FROM_ECLIPSE_TO_PYTHON to map to my python script path against this <script > like this [["D:/debugTestPython/script.py","<string>"]].
*
Then it worked ,it opens the correct python script as mentioned in the env path but it opens a new tab with same script file in vscode.
Any solution to solve this problem.?
Thanks in advance
Regards
Sathishkumar
…________________________________
From: Sathishkumar Jeevanantham ***@***.***>
Sent: 16 October 2024 02:32 AM
To: microsoft/debugpy ***@***.***>; microsoft/debugpy ***@***.***>
Cc: Author ***@***.***>
Subject: Re: [microsoft/debugpy] Not able to attach to a sub process (Discussion #1698)
HI Rich Chiodo,
*
Thanks for taking time to respond my query
*
I actually found the issue and resolved it.
*
I had path mappings which was causing the issue i removed it - then it worked like a magic
*
But i had to call configure method before calling listen - in python script otherwise not attaching.
Python Script
debugpy.configure(subprocess=False)
debugpy.listen(5678)
debugpy.wait_for_client() # This will pause the execution until a debugger attaches
debugpy.breakpoint()
config json:
"configurations": [
{
"name": "Python Debugger: Remote Attach",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"justMyCode": false
}
]
My Pythonnet c# code :
PythonEngine.PythonHome = @"C:\Users\SATHISHKUMAR\AppData\Local\Programs\Python\Python39";
// Add the Python standard library to Python path
PythonEngine.PythonPath = Environment.GetEnvironmentVariable("PYTHONPATH") + ";" +
@"C:\Users\SATHISHKUMAR\AppData\Local\Programs\Python\Python39\Lib";
PythonEngine.DebugGIL = true;
PythonEngine.Initialize();
try
{
string pythonScriptPath = "D:\\debugTestPython\\script.py";
if (File.Exists(pythonScriptPath))
{
string script = File.ReadAllText(pythonScriptPath);
using (Py.GIL()) // Ensures proper handling of Python Global Interpreter Lock (GIL)
{
// Execute the Python code
PythonEngine.Exec(script);
}
}
else
{
Console.WriteLine($"File {pythonScriptPath} not found.");
}
//PythonEngine.Shutdown();
}
*
Now i can able to attach but whenever i inspect a variable the tool crashes. Any solution.?
*
Anything wrong in my configuration or script - kindly share your suggestions to improve.
Regards
Sathishkumar Jeevanantham
________________________________
From: Rich Chiodo ***@***.***>
Sent: 14 October 2024 09:34 PM
To: microsoft/debugpy ***@***.***>
Cc: JeevananthamSathish ***@***.***>; Author ***@***.***>
Subject: Re: [microsoft/debugpy] Not able to attach to a sub process (Discussion #1698)
Can you share some example code? I can try it myself.
Reading about Pythonnet<https://pythonnet.github.io/> it sounds like it should work, but there might be something that pythonnet is doing that messes up attach.
There's also a logToFile setting you can set in VS code's launch.json. This will output a bunch of log files in your \ms-python.debugpy- folder.
—
Reply to this email directly, view it on GitHub<#1698 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/BFKDN7VJUDVKLCMY6MFVAM3Z3PTQBAVCNFSM6AAAAABP2PO2DKVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTAOJTHA3TONI>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a created a c# exe app where i used pythonnet and running a python script inside the dotnet app as a sub-process . I am trying to debug the python script which is running inside the donet app but in vscode i am not able to achieve this. I tried remote debugging with connect listen logic ... kindly help me with debugging the python subprocess script ...
Beta Was this translation helpful? Give feedback.
All reactions