热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

我在C#-Application中成功实现了IronPython.我将所有脚本存储在数据库中,并在需要时加载它们.现在我想用PTVS调试我的Python代码.但总是当我尝试连接远程

我在C#-Application中成功实现了IronPython.我将所有脚本存储在数据库中,并在需要时加载它们.现在我想用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.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.0
string dir = Path.GetDirectoryName("C:\\Support\\Modules\\ptvsd");
ICollection 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 optiOns= new Dictionary();
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
# --------------------------------------------
# --------------------------------------------
#


#Eine Instanz dieser Klasse wird automatisch mit
#dem Start des DocCenter Studios erstellt.
#

class StudioInstance:
# --------------------------------------------
# Declarations
# --------------------------------------------
# --------------------------------------------
# Constructor
def __init__(self):
pass
# --------------------------------------------
# --------------------------------------------
# Will be called before the Login-Window open
def BeforeUserLogin(self):
try:
pass
except:
pass
# --------------------------------------------
# --------------------------------------------
#
#Wird ausgeführt, wenn der Login für einen Benutzer
# Fehlschlägt
#

#

Eingegeber Benutzername
#

Eingegebene Domain


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连接,但我不确定).


推荐阅读
author-avatar
销魂苗苗若郗
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有