Why don't breakpoints work on Swing Event Dispatch Thread in PyDev?

I use Jython, Swing and PyDev (Eclipse).

Breakpoints do not fall into any code that runs on EDT (aka AWT Event Queue?).

It includes:

  • Functions called from a Swing event (e.g. JButton click)
  • Functions that go through the decorator SwingUtilities.invokeLater()(see the last example here .
  • Functions registered as interceptors of the Java package (socket class) that I use.

Swing event code to play:

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 play:

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)
0
source share
1 answer

Jython.

I.e: , TestFunc, trace_dispatch, .

, Jython , . "" PyDev, import pydevd;pydevd.settrace(suspend=False), ( : TestFunc ).

: suspend = False, .

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
+1

Source: https://habr.com/ru/post/1768582/


All Articles