Skip to content

Unable to get Mixed mode debugging working in python 3.9.6 + pythonnet 2.5.2 #1740

@guytaylor

Description

@guytaylor

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:

  1. Build
  2. From a command prompt, run the app
    • I get the prompt waiting for .net debugger to attach
  3. I attach the debugger like this:

pic1

This is what it looks like after attaching:

debug

  1. The app continues, and you can see the output:

console

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

pic3break

This is what my modules look like:
pics2mods

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions