Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importing AWT classes hangs the script on OSX #151

Open
codeanticode opened this issue Mar 2, 2015 · 3 comments
Open

importing AWT classes hangs the script on OSX #151

codeanticode opened this issue Mar 2, 2015 · 3 comments
Labels
platform-osx support upstream Topics related to changes/bugs/quirks in upstream PyJNIus uses. (Python, Java, specific JNI, ...)

Comments

@codeanticode
Copy link

codeanticode commented Mar 2, 2015

This python script:

from jnius import autoclass
print "hello jnius"
Frame = autoclass("java.awt.Frame")
print "bye jnius"

hangs when loading the Frame class (runnning OSX 10.9.5, JDK 1.8.0_31). I'm aware of issues with AWT on OSX #85, where a suggested workaround is to use -Djava.awt.headless=true.

But if I explicitly don't want to use the headless mode, is there ant workaround to this issue?


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@tpietzsch
Copy link

I had the same problem and here is a solution/workaround. For AWT to work, the cocoa main loop needs to be started. This can be done outside jnius. Something like this works for me:

import objc
from Foundation import *
from AppKit import *
from PyObjCTools import AppHelper

def runAwtStuff():
    # main program goes here

class AppDelegate (NSObject):
    def runjava_(self,arg):
        runAwtStuff()

    def applicationDidFinishLaunching_(self, aNotification):
        self.performSelectorInBackground_withObject_("runjava:",0)

def main():
    app = NSApplication.sharedApplication()
    delegate = AppDelegate.alloc().init()
    NSApp().setDelegate_(delegate)
    AppHelper.runEventLoop()

if __name__ == '__main__' : main()

@codeanticode
Copy link
Author

@tpietzsch many thanks for sharing the workaround! I'm not using Pyjnius at the moment, but will give it a try as soon as I have a chance.

ctrueden added a commit to imagej/pyimagej that referenced this issue Apr 20, 2018
This avoids problems with AWT on macOS.

The alternative is to use the OSXAWTwrapper approach
from https://github.com/hanslovsky/imglib2-imglyb.

See also:
kivy/pyjnius#151 (comment)
@KeyWeeUsr KeyWeeUsr added support upstream Topics related to changes/bugs/quirks in upstream PyJNIus uses. (Python, Java, specific JNI, ...) platform-osx labels Feb 1, 2019
machristie added a commit to SciGaP/simccs-maptool that referenced this issue May 28, 2019
This fixes the issue with generating shapefiles where loading
openmap's EsriPointList would hang. Some of openmap's classes,
like EsriPointList, depend on AWT classes and this causes pyjnius to
hang on macOS.  See kivy/pyjnius#151 for
more details.
@frederikschubert
Copy link

@tpietzsch The workaround works great! For anyone who also stumbles upon this issue: the needed lib can be installed via

pip install -U pyobjc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-osx support upstream Topics related to changes/bugs/quirks in upstream PyJNIus uses. (Python, Java, specific JNI, ...)
Projects
None yet
Development

No branches or pull requests

4 participants