My java / jython app runs a ‘default’ SWT main loop like this:
while not shell.isDisposed():
if not display.readAndDispatch():
display.sleep()
On Mac OS X, all SWT-related code needs to run in the main thread, as follows:
from com.apple.concurrent import Dispatch
call = Dispatch.getInstance().getNonBlockingMainQueueExecutor().execute
class Main(Runnable):
def run(self):
# main loop here
call(Main())
So far this works fine. Now to the problematic part: I need, at some point in time, execute SWT-related code from outside of the Main.run method.
When I use the same call() magic while the main loop is running, nothing happens since the thread is busy (the async call as shown above returns immediately, but never executes any code, and synchronous call blocks forever).
Shouldn’t display.readAndDispatch() actually process these calls? Is there any way I can execute code on this thread in clean fashion (that is, without building an event queue of my own)?
Reimplementing this stuff inside of the main loop would be relatively easy, but I feel like I’m missing something very obvious here.
Figured this out,
display.asyncExecdoes just that.