Environment
- Pythonnet version: 2.5.2
- Python version: 3.9.6
- Operating System: windows 10
- .NET Runtime: 4.6.2
Details
- Describe what you were trying to get done.
I am trying to get mixed mode debugging working. I have a c# app which calls python and I would like to be able to debug into the python code.
I've followed the instruction here: https://github.com/pythonnet/pythonnet/wiki/Various-debugging-scenarios-of-embedded-CPython
and worked my way through this thread: #332
This is the C# app:
public class Program
{
public static void EnableDebugging()
{
Console.WriteLine("waiting for .NET debugger to attach");
while (!Debugger.IsAttached)
{
Thread.Sleep(100);
}
Console.WriteLine(".NET debugger is attached");
}
public static void Main(string[] args)
{
string pythonHome = @"C:\Python39";
string pythonPath = pythonHome + @"\DLLs;" + pythonHome + @"\Lib;" + pythonHome + @"\Lib\site-packages";
pythonPath += ";" + @"C:\Users\gtaylor\Downloads\EmbeddedPythonDebugging-master\EmbeddedPythonDebugging\bin\Debug";
string path = pythonHome + ";" + Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine);
Environment.SetEnvironmentVariable("PATH", path, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("PYTHONHOME", pythonHome, EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("PYTHONPATH ", pythonPath, EnvironmentVariableTarget.Process);
PythonEngine.PythonHome = pythonHome;
PythonEngine.PythonPath = pythonPath;
PythonEngine.Initialize();
EnableDebugging();
using (Py.GIL())
{
PythonEngine.ImportModule("testmodule");
}
}
}
In the project conditional compilation symbols are: PYTHON3;PYTHON39;UCS2
The python code in testmodule.py is:
import time
while True:
print ("Hello world..") # set a break point here
These are steps I take to run it:
- Build
- From a command prompt, run the app
- I get the prompt
waiting for .net debugger to attach
- I attach the debugger like this:

This is what it looks like after attaching:

- The app continues, and you can see the output:

- My breakpoint is never hit. I have tried this with both the 32bit and 64bit version. (I need 64 bit for my application)

This is what my modules look like:

Environment
Details
I am trying to get mixed mode debugging working. I have a c# app which calls python and I would like to be able to debug into the python code.
I've followed the instruction here: https://github.com/pythonnet/pythonnet/wiki/Various-debugging-scenarios-of-embedded-CPython
and worked my way through this thread: #332
This is the C# app:
In the project conditional compilation symbols are:
PYTHON3;PYTHON39;UCS2The python code in testmodule.py is:
These are steps I take to run it:
waiting for .net debugger to attachThis is what it looks like after attaching:
This is what my modules look like:
