IronPython Remote Debugging with PTVS

I have successfully implemented IronPython in my C # -Application. I save all my scripts in a database and load them when they are needed. Now I want to debug my Python code with PTVS. But always, when I try to connect to a remote debugger with my application, visual studio says what I should use ptvsd.enable_attach().

  • I thought that if I turn on Debug mode for my Python-Engine, that would be enough.
  • If I need to import ptvsd, how can I import scripts ( ini , main , ...), should I put them also in my database?

I can’t figure it out and tried a lot, but nothing works.

EDIT : I could figure out how to use ptvsd, I have to "enable" the ptvsd module:

//copied from: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.0

string dir = Path.GetDirectoryName("C:\\Support\\Modules\\ptvsd");
ICollection<string> paths = myScriptEngine.GetSearchPaths();

if (dir != null && dir != "")
{
    paths.Add(dir);
}
else
{
    paths.Add(Environment.CurrentDirectory);
}

But now I get an error message in os.py:

global name statvfs_result not defined

in lines:

_copy_reg.pickle(statvfs_result, _pickle_statvfs_result,
    _make_statvfs_result)

EDIT 2 . It seems I can ignore the error message with a global name. But now I get the following message:

IronPython must be started with the -X: Tracing and -X: Frames options to support remote PTVS debugging.

EDIT 3 : I solved the error with trace and frames using the following code:

        Dictionary<string, object> options = new Dictionary<string, object>();
        options["Debug"] = true;
        options["Tracing"] = true;
        options["Frames"] = true;
        myScriptEngine = Python.CreateEngine(options);

But now I have the following problem: I can’t connect the visual studio to my application, I always get the following error message:

Python "localhost: 5678". , ptvsd.enable_attach() -

4: python:

# -----------------------------------------------
# Framework-Root-Script
# This script is the main-framework script
#  Autor: BE
#  Date: 07.10.2013
# -----------------------------------------------

# --------------------------------------------
import sys
#import atexit
import ptvsd

ptvsd.enable_attach(None)
#ptvsd.wait_for_attach()

#
from System import *
from System.Windows import MessageBox
from System.Windows.Controls import Grid, MenuItem
from ESS.MS.Base import GlobalSettings
from ESS.MS.Framework.Core.TaskbarNotification import TaskbarNotificationManager
from ESS.MS.Framework.UIG.Mask import DynamicMaskManager
# --------------------------------------------

# --------------------------------------------
#<summary>
#Eine Instanz dieser Klasse wird automatisch mit
#dem Start des DocCenter Studios erstellt.
#</summary>
class StudioInstance:

    # --------------------------------------------
    # Declarations

    # --------------------------------------------

    # --------------------------------------------
    # Constructor
    def __init__(self): 
        pass 
    # --------------------------------------------

    # --------------------------------------------
    # Will be called before the Login-Window open
    def BeforeUserLogin(self):
        try:
            pass
        except:
            pass
    # --------------------------------------------

    # --------------------------------------------
    #<summary>
    #Wird ausgeführt, wenn der Login für einen Benutzer
    # Fehlschlägt
    #</summary>
    #<param Name="InputUserName">Eingegeber Benutzername</param>
    #<param Name="InputDomain">Eingegebene Domain<param>
    def LoginFailed(self, InputUserName, InputDomain):
        try:
            pass
        except:
            pass
    # --------------------------------------------

    # --------------------------------------------
    # Will be called if the Login-Process is complete
    def LoginComplete(self, UserName, Domain):
        try:
            # -------------------------------------------------------------------
            # Control auf das Tray-Icon setzten (Linksklick)
            # Mask = DynamicMaskManager.Singleton.GetMaskInstance("Win_DCC_Bediener", False)

            # grid = Grid()
            # grid.Children.Add(Mask.VisualElement)

            # TaskbarNotificationManager.Singleton.AddTrayPopupControl(grid)
            # -------------------------------------------------------------------

            # -------------------------------------------------------------------
            # Context-Menu einttrag auf das Tray-Icon setzten
            # test = MenuItem()
            # test.Header = "Hallo Welt"
            # TaskbarNotificationManager.Singleton.AddContextMenuItem(test)
            # -------------------------------------------------------------------
            pass
        except Exception, e:
            MessageBox.Show(e.ToString())
    # --------------------------------------------

    # --------------------------------------------
    # Will be called synchron with the UI (same thread)
    def SyncUpdate(self):
        try:
            pass
        except Exception, e:
            MessageBox.Show(e.ToString())
    # --------------------------------------------

    # --------------------------------------------
    # Will be called in a custom thread
    def AsyncUpdate(self):
        try:
            pass
        except:
            pass
    # --------------------------------------------

# --------------------------------------------

5 , . , .

Refresh-Button: Scrennshot

- , !

+4
2

, localhost, ptvsd.enable_attach(), , . , Windows, ( , , ).

+1

. attach_server.py , server_thread_func(). . , , . .

visualstudio_py_util.py::write_bytes() .., , / .

0

Source: https://habr.com/ru/post/1531242/


All Articles