i've implemented IronPython in my C#-Application successful. I store all my scripts in a database and load them when they are needed. Now i want to debug my Python-Code with the PTVS. But always when i try to connect with the remote debugger to my application the visual studio say that i should use ptvsd.enable_attach()
.
- i thought if i enable the Debug-Mode for my Python-Engine it would be enought
- If i need to import ptvsd, how i can import the scripts(ini, main, ...) should i put them also in my database?
I can't figure this points out and have tried a lot, but nothing realy work.
EDIT: I could figure out how to use ptvsd, i have to "include" 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 in os.py:
global name 'statvfs_result' is not defined
in the lines:
_copy_reg.pickle(statvfs_result, _pickle_statvfs_result,
_make_statvfs_result)
EDIT 2: It seems that i can ignore the error message with the global name. But now i get the following message:
IronPython must be started with -X:Tracing and -X:Frames options to support PTVS remote debugging.
EDIT 3: I solved the error with Tracing and Frames by 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 next problem, i can't attach visual studio to my application, i get always the following error-message:
Could not connect to remote Python process at 'localhost:5678'. Make sure that the process is running, and has called ptvsd.enable_attach()-
EDIT 4: My python code:
# -----------------------------------------------
# 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
# --------------------------------------------
# --------------------------------------------
EDIT 5 I think i can attach now to the process. But when i click on the refresh-button in the visual studio debugger window, visual studio hang up and the program doesn't react anymore.
Refresh-Button:
Maybe some one can halp me, thank you!