Is there a way to debug Python code embedded in C # with Visual Studio and PTVS?

I have created a code to embed IronPython code in C #

    public ScriptEngine GetEngine() {
        if( _engine != null )
            return _engine;

        _engine = Python.CreateEngine();
        var paths = _engine.GetSearchPaths();
        paths.Add( _pythonPath );
        _engine.SetSearchPaths( paths );

        var runtime = _engine.Runtime;
        runtime.LoadAssembly( typeof( CharacterCore ).Assembly );
        return _engine;
    }

    public IAbility Movement() {
        var engine = GetEngine();
        var script = engine.CreateScriptSourceFromFile( Path.Combine( _pythonPath, "movement.py" ) );
        var code = script.Compile();
        var scope = engine.CreateScope();
        code.Execute( scope );

        return scope.GetVariable( "result" );
    }

      

with the corresponding Python code in a separate Python project in the same solution. The code itself works, but if I set a breakpoint in the Python code, it never hits. Is there a way to do a debugger step in Python code?

I am using Visual Studio 2015 RC (also Visual Studio 2013), Python Tools for Visual Studio (with IronPython Launcher for Python code). I tried to create script source from string and from file, debug never works.

+3


source to share


1 answer


Adding parameters to CreateEngine like

var options = new Dictionary<string, object> { ["Debug"] = true };
_engine = Python.CreateEngine( options );

      



and disable "Just My Code" in the Debug options allowed for debugging embedded Python, including breakpoints and breakpoints.

Kudos where they should, thanks to Pavel Minaev and Joe in the comments on the question.

+3


source







All Articles