为什么在PyDev中的Swing Event Dispatch Thread上没有断点工作? [英] Why aren't breakpoints working on the Swing Event Dispatch Thread in PyDev?
问题描述
我正在使用Jython,Swing和PyDev(Eclipse)。
I'm using Jython, Swing, and PyDev (Eclipse).
断点不会在EDT上运行的任何代码(也称为AWT事件队列
Breakpoints are not being hit on any code that runs on the EDT (aka AWT Event Queue?).
这包括:
- 从Swing调用的函数事件(例如JButton点击)
- 通过装饰器运行的函数通过
SwingUtilities.invokeLater()
(参见最后一个例子 here 。 - 注册为Java包(套接字类)的挂钩的函数,我正在使用。
- 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事件代码重现:
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()代码: / p>
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)
推荐答案
这实际上是一个Jython问题。
It's actually a Jython issue.
Ie:在下面的代码中,当调用TestFunc时,打印从t他应该调用trace_dispatch,但不是这样。
I.e.: in the code below, when TestFunc is called, the print from the trace_dispatch should be called, but it's not.
所以,Jython跟踪实现不是在这种情况下调用跟踪功能。您可以通过调用 import pydevd; pydevd.settrace(suspend = False)
来帮助PyDev调试器,以便调试器发现该框架(即:在TestFunc开始时)添加一行代码)。
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).
请注意,如果不传递suspend = False,它将作为代码中的断点,并将停止该行的执行。
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.
import sys
import threading
def trace_dispatch(frame, event, arg):
print frame.f_code.co_filename, frame.f_code.co_name
sys.settrace(trace_dispatch)
threading.settrace(trace_dispatch)
from javax.swing import JFrame, JButton
def TestFunc(event):
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
这篇关于为什么在PyDev中的Swing Event Dispatch Thread上没有断点工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!