加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 22:02:21 所属栏目:百科 来源:网络整理
导读:我在C#-Application中成功实现了Iron Python.我将所有脚本存储在数据库中,并在需要时加载它们.现在我想用PTVS调试我的Python代码.但总是当我尝试连接远程调试器到我的应用程序时,visual studio说我应该使用ptvsd.enable_attach(). 我想如果我启用我的Python-
我在C#-Application中成功实现了Iron Python.我将所有脚本存储在数据库中,并在需要时加载它们.现在我想用PTVS调试我的Python代码.但总是当我尝试连接远程调试器到我的应用程序时,visual studio说我应该使用ptvsd.enable_attach().

>我想如果我启用我的Python-Engine的调试模式,它将是应该的
>如果我需要导入ptvsd,我如何导入脚本(ini,main,…)我应该将它们也放在我的数据库中吗?

我无法弄清楚这一点,并尝试了很多,但没有任何真正的工作.

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

//copied from: C:Program Files (x86)Microsoft Visual Studio 11.0Common7IDEExtensionsMicrosoftPython Tools for Visual Studio2.0

string dir = Path.GetDirectoryName("C:SupportModulesptvsd");
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:我使用以下代码解决了跟踪和帧的错误:

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挂断,程序不再响应.

刷新按钮:

也许有人可以打扰我,谢谢!

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读