c# – 使用PTVS进行IronPython远程调试
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 使用PTVS进行IronPython远程调试,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4940字,纯文字阅读大概需要8分钟。
内容图文
我在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<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连接,但我不确定).
内容总结
以上是互联网集市为您收集整理的c# – 使用PTVS进行IronPython远程调试全部内容,希望文章能够帮你解决c# – 使用PTVS进行IronPython远程调试所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。