gpt4 book ai didi

c# - 使用 PTVS 进行 IronPython 远程调试

转载 作者:太空宇宙 更新时间:2023-11-03 11:52:37 26 4
gpt4 key购买 nike

我已经在我的 C# 应用程序中成功实现了 IronPython。我将所有脚本存储在数据库中,并在需要时加载它们。现在我想用 PTVS 调试我的 Python 代码。但是当我尝试将远程调试器连接到我的应用程序时,visual studio 总是说我应该使用 ptvsd.enable_attach()

  1. 我想如果我为我的 Python 引擎启用 Debug模式就足够了
  2. 如果我需要导入 ptvsd,我应该如何导入脚本(inima​​in、...)我是否应该将它们也放入我的数据库中?<

我想不出这一点并尝试了很多,但没有任何效果。

编辑:我可以弄清楚如何使用 ptvsd,我必须“包含”ptvsd 模块:

//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 中得到一个错误:

global name 'statvfs_result' is not defined

行内:

_copy_reg.pickle(statvfs_result, _pickle_statvfs_result,
_make_statvfs_result)

编辑 2:似乎我可以忽略带有全局名称的错误消息。但现在我收到以下消息:

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

编辑 3:我使用以下代码解决了 Tracing and Frames 的错误:

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

但现在我遇到了下一个问题,我无法将 visual studio 附加到我的应用程序,我总是收到以下错误消息:

Could not connect to remote Python process at 'localhost:5678'. Make sure that the process is running, and has called 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我想我现在可以附加到流程中。但是当我在 visual studio 调试器窗口中单击刷新按钮时,visual studio 挂断并且程序不再有反应。

刷新按钮: Scrennshot

也许有人可以阻止我,谢谢!

最佳答案

假设进程在 localhost 上运行并且您调用了 ptvsd.enable_attach(),这可能是防火墙问题。您可能需要调整 Windows 防火墙以允许连接到该端口(我认为始终允许本地主机连接,但我不确定)。

关于c# - 使用 PTVS 进行 IronPython 远程调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22336460/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com