为什么断点在 PyDev 中的 Swing 事件调度线程上不起作用?
我正在使用 Jython、Swing 和 PyDev (Eclipse)。
在 EDT(又名 AWT 事件队列?)上运行的任何代码都不会命中断点。
这包括:
- 从 Swing 事件(例如 JButton 单击)调用的函数
- 通过装饰器通过
SwingUtilities.invokeLater()
运行的函数(请参阅最后一个示例 此处 - 注册为 Java 包(套接字)的函数 。类),我正在使用
Swing 事件代码 。重现:
from javax.swing import JFrame, JButton
def TestFunc(event):
#breakpoints in this function don't work
print "Hey"
if __name__ == '__main__':
mainWindow = JFrame('Test',
defaultCloseOperation = JFrame.EXIT_ON_CLOSE,
size = (1024, 600))
mainWindow.add(JButton("Hey", actionPerformed = TestFunc))
mainWindow.visible = True
invokeLater() 重现代码:
from java.lang import Runnable
from javax.swing import SwingUtilities
import threading
class foo(Runnable):
def __init__(self, bar):
self.bar = bar
def run(self):
#breakpoints in this function don't work
print threading.currentThread()
print self.bar
if __name__ == '__main__':
myFoo = foo(5)
SwingUtilities.invokeLater(myFoo)
I'm using Jython, Swing, and PyDev (Eclipse).
Breakpoints are not being hit on any code that runs on the EDT (aka AWT Event Queue?).
This includes:
- Functions that are invoked from a Swing event (eg JButton click)
- Functions that, via a decorator, are run through
SwingUtilities.invokeLater()
(See the last example here. - Functions that registered as hooks to a Java package (socket class), that I'm using.
Swing event code to reproduce:
from javax.swing import JFrame, JButton
def TestFunc(event):
#breakpoints in this function don't work
print "Hey"
if __name__ == '__main__':
mainWindow = JFrame('Test',
defaultCloseOperation = JFrame.EXIT_ON_CLOSE,
size = (1024, 600))
mainWindow.add(JButton("Hey", actionPerformed = TestFunc))
mainWindow.visible = True
invokeLater() code to reproduce:
from java.lang import Runnable
from javax.swing import SwingUtilities
import threading
class foo(Runnable):
def __init__(self, bar):
self.bar = bar
def run(self):
#breakpoints in this function don't work
print threading.currentThread()
print self.bar
if __name__ == '__main__':
myFoo = foo(5)
SwingUtilities.invokeLater(myFoo)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这实际上是一个 Jython 问题。
即:在下面的代码中,当调用 TestFunc 时,应该调用来自trace_dispatch 的打印,但事实并非如此。
因此,Jython 跟踪实现没有像在这种情况下那样调用跟踪函数。您可以通过调用 import pydevd;pydevd.settrace(suspend=False) 来“帮助”PyDev 调试器,以便调试器发现该帧(即:在 TestFunc 的开头添加该行代码) 。
请注意,如果您不传递 suspend=False,它将充当代码中的断点并在该行停止执行。
It's actually a Jython issue.
I.e.: in the code below, when TestFunc is called, the print from the trace_dispatch should be called, but it's not.
So, the Jython tracing implementation is not calling the tracing function as it should in that situation. You can 'help' the PyDev debugger by calling
import pydevd;pydevd.settrace(suspend=False)
so that the debugger discovers about that frame (i.e.: in the start of TestFunc add that line of code).Note that if you don't pass the suspend=False, it'll act as a breakpoint in the code and will stop the execution at that line.