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

如何在开发过程中调试优秀的插件-Howtodebugsublimepluginsduringdevelopment

Iwanttodebugmypluginwithpdbbutitdoesntwork.Igettheseerrors我想用pdb调试我的插件,但是它不起作用。我得到了

I want to debug my plugin with pdb but it doesn't work. I get these errors

我想用pdb调试我的插件,但是它不起作用。我得到了这些错误

Traceback (most recent call last):
  File "./sublime_plugin.py", line 362, in run_
  File "./useIt.py", line 14, in run
    for region in self.view.sel():
  File "./useIt.py", line 14, in run
    for region in self.view.sel():
  File ".\bdb.py", line 46, in trace_dispatch
  File ".\bdb.py", line 65, in dispatch_line
bdb.BdbQuit

Has anyone an idea? Or some other way to debug a sublime plugin?

有人知道吗?或者用其他方法来调试一个优秀的插件?

3 个解决方案

#1


17  

The problem is that sys.stdin is not attached to anything normally. But, sys.stdin does work if you start SublimeText2 from a console:

问题是系统。stdin通常不连接任何东西。但是,系统。如果从控制台启动SublimeText2,则stdin确实有效:

  • On Mac, start the application by locating the executable in the resource bundle by entering the full path in the Terminal:

    在Mac上,通过输入终端的完整路径,在资源包中定位可执行文件,启动应用程序:

    /Applications/Sublime\ Text\ 2.app/Contents/MacOS/Sublime\ Text\ 2
    
  • On Windows, start the application from the Windows Console:

    在Windows上,从Windows控制台启动应用程序:

    "C:\Program Files\Sublime Text 2\sublime_text.exe"
    

    provisional, I have no Windows Sublime Text 2 install so this command line is based on a quick Google

    临时,我没有安装Windows崇高文本2,所以这个命令行基于一个快速的谷歌

Now the application has a console; but sys.stdout is still redirected to the built-in SublimeText 2 console. You want to start your debugger with the correct stdout, the one still connected to your console. Instead of import pdb; pdb.set_trace(), use:

现在应用程序有了一个控制台;但系统。stdout仍然被重定向到内置的SublimeText 2控制台。您希望使用正确的stdout启动调试器,这个stdout仍然连接到控制台。而不是进口pdb;pdb.set_trace(),使用:

import pdb, sys; pdb.Pdb(stdout=sys.__stdout__).set_trace()

The original console stdout is saved in sys.__stdout__ and by passing that to pdb.Pdb() you get a fully functional pdb session.

原始控制台stdout保存在sys中。__stdout__并将其传递给pdb. pdb(),您将得到一个完全功能的pdb会话。

#2


2  

Working on my plugin, I didn't have much luck with pdb, and "print" is not an efficient debugging experience (for example, if you aren't sure where the defect is, you might add a lot of "print" - and then have to remove them after).

在我的插件上工作时,我对pdb不太满意,而且“打印”也不是一个有效的调试体验(例如,如果您不确定缺陷在哪里,您可能会添加很多“打印”——然后必须在之后删除它们)。

There is a much better alternative if you run Windows. The latest version 2.2 of the Python tools for Visual Studio works great for debugging Sublime plugins. You get all the regular debugging features of Visual Studio and it's a polished experience. Just choose "pluginhost.exe" and the Python debugging engine in the attach dialog. Previous to 2.2, the Python tools did not work properly against Sublime, for example stepping was broken.

如果你运行Windows,还有一个更好的选择。Visual Studio的Python工具的最新版本2.2非常适合调试卓越的插件。您可以获得Visual Studio的所有常规调试特性,这是一种完美的体验。选择“pluginhost。和附加对话框中的Python调试引擎。在2.2之前,Python工具在与Sublime对抗时不能正常工作,例如,step被破坏。

Disclosure: I work in Visual Studio but do not work on these tools. I recently worked with the Python tools developer to fix the bugs I encountered using these tools to write my plugin.

披露:我在Visual Studio工作,但不使用这些工具。我最近与Python工具开发人员合作,修复我使用这些工具编写插件时遇到的bug。

The Community Edition of Visual Studio 2015 is free to individual developers and small organizations. Just make sure you check Python tools in the setup dialog. And, of course, you must be running Windows.

Visual Studio 2015的社区版对个人开发人员和小型组织是免费的。请确保在设置对话框中检查Python工具。当然,你一定是在运行Windows。

#3


1  

Your problem is that sys.stdin and sys.stdout (Edit: stdout goes to the console) are connected into the internals of sublime text - where do you expect to be able to control the debugger?

你的问题是系统。stdin和系统。stdout(编辑:stdout转到控制台)连接到崇高文本的内部—您期望在哪里能够控制调试器?

What you want is a remote debugging interface that interacts through something other than stdio, such as rpdb.

您需要的是一个远程调试接口,它通过stdio之外的其他东西进行交互,比如rpdb。


推荐阅读
  • 带添加按钮的GridView,item的删除事件
    先上图片效果;gridView无数据时显示添加按钮,有数据时,第一格显示添加按钮,后面显示数据:布局文件:addr_manage.xml<?xmlve ... [详细]
  • 本文介绍了在Win10上安装WinPythonHadoop的详细步骤,包括安装Python环境、安装JDK8、安装pyspark、安装Hadoop和Spark、设置环境变量、下载winutils.exe等。同时提醒注意Hadoop版本与pyspark版本的一致性,并建议重启电脑以确保安装成功。 ... [详细]
  • Struts2+Sring+Hibernate简单配置
    2019独角兽企业重金招聘Python工程师标准Struts2SpringHibernate搭建全解!Struts2SpringHibernate是J2EE的最 ... [详细]
  • 第一步:PyQt4Designer设计程序界面该部分设计类同VisvalStudio内的设计,改下各部件的objectName!设计 ... [详细]
  • 转载:MFC 获得各类指针、句柄的方法
    2019独角兽企业重金招聘Python工程师标准转载:最近有些人在问MFC编程一些要点,有一些句柄的获取、指针的获取是 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • FeatureRequestIsyourfeaturerequestrelatedtoaproblem?Please ... [详细]
  • 恶意软件分析的最佳编程语言及其应用
    本文介绍了学习恶意软件分析和逆向工程领域时最适合的编程语言,并重点讨论了Python的优点。Python是一种解释型、多用途的语言,具有可读性高、可快速开发、易于学习的特点。作者分享了在本地恶意软件分析中使用Python的经验,包括快速复制恶意软件组件以更好地理解其工作。此外,作者还提到了Python的跨平台优势,使得在不同操作系统上运行代码变得更加方便。 ... [详细]
  • Mono为何能跨平台
    概念JIT编译(JITcompilation),运行时需要代码时,将Microsoft中间语言(MSIL)转换为机器码的编译。CLR(CommonLa ... [详细]
  • 抽空写了一个ICON图标的转换程序
    抽空写了一个ICON图标的转换程序,支持png\jpe\bmp格式到ico的转换。具体的程序就在下面,如果看的人多,过两天再把思路写一下。 ... [详细]
  • ExcelApp#启动excel程序ExcelAppCreateOleObject(“Excel.Application”);#加载文件但不显示文件内容(true表 ... [详细]
  • .babelrc是用来设置转码规则和插件的,这种文件在window上无法直接创建,也无法在HBuilder中创建,甚至无法查看,但可以在sublimetext中创建、查看并编辑。当 ... [详细]
  • 1.修改babelrc文件{presets:[es2015,react,stage-1],plugins:[transform-decorators-lega ... [详细]
author-avatar
雪染苍原牛仔
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有