C# アプリケーションに IronPython を実装しました。すべてのスクリプトをデータベースに保存し、必要なときにロードします。ここで、PTVS を使用して Python コードをデバッグしたいと考えています。しかし、常にリモート デバッガーを使用してアプリケーションに接続しようとすると、ビジュアル スタジオはptvsd.enable_attach()
.
- Python-Engine のデバッグ モードを有効にすれば十分だと思いました
- ptvsd をインポートする必要がある場合、スクリプト ( ini、mainなど) をインポートするにはどうすればよいですか?
この指摘を理解できず、多くのことを試しましたが、実際には何も機能しません。
編集: ptvsd の使用方法を理解できました。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);
}
しかし、今は os.py でエラーが発生します:
グローバル名 'statvfs_result' が定義されていません
行で:
_copy_reg.pickle(statvfs_result, _pickle_statvfs_result,
_make_statvfs_result)
EDIT 2 :グローバル名のエラーメッセージを無視できるようです。しかし、今では次のメッセージが表示されます。
PTVS リモート デバッグをサポートするには、IronPython を -X:Tracing および -X:Frames オプションで開始する必要があります。
EDIT 3 :次のコードを使用して、トレースとフレームでエラーを解決しました:
Dictionary<string, object> options = new Dictionary<string, object>();
options["Debug"] = true;
options["Tracing"] = true;
options["Frames"] = true;
myScriptEngine = Python.CreateEngine(options);
しかし今、次の問題があります。Visual Studio をアプリケーションにアタッチできません。常に次のエラー メッセージが表示されます。
「localhost:5678」でリモート Python プロセスに接続できませんでした。プロセスが実行中で、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
# --------------------------------------------
# --------------------------------------------
EDIT 5 今すぐプロセスに添付できると思います。しかし、Visual Studio デバッガー ウィンドウの更新ボタンをクリックすると、Visual Studio がハングアップし、プログラムが反応しなくなります。
更新ボタン:
多分誰かが私を半分にすることができます、ありがとう!