I am trying to run a python program ( sikuli ) that imports a jar using jnius. This is the gist of the code in sikuli package that loads the jar file in python
import os
jarpath = "/Users/*/sikuli-api-1.0.3-standalone.jar"
os.environ['CLASSPATH'] = jarpath
from jnius import autoclass
DesktopMouse = autoclass('org.sikuli.api.robot.desktop.DesktopMouse')
aa = DesktopMouse()
gg = aa.getLocation()
This code runs without any problem when I run in windows. But when I run this in mac, the program hangs with a java icon in the dock. . and I get this error/message in the logs when I run the python script.
launchservicesd: SecTaskLoadEntitlements failed error=22
appleeventsd: SecTaskLoadEntitlements failed error=22
Can anyone say what this error means ( or the reason for the hang/java icon in the dock )? I would like to debug the reason for this hang but any help in debugging this error would be welcome.
There are two answers to your question about the dock icon, the first about why it appears and the second about why it remains:
Unless the JVM is launched with
-Djava.awt.headless=true
, then the JVM will initialize the GUI subsystem (AWT or Swing) when a running program first accesses a class or method in it. One can trivially see this in action using thejjs
program in the JRE:This command will run but will not cause the dock icon:
echo 'java.lang.System.out.println("hello")' | $JAVA_HOME/jre/bin/jjs
This command will run but will cause the dock icon:
printf 'var f = new javax.swing.JFrame("frame 1")\nf.setVisible(true)\n' | \ $JAVA_HOME/jre/bin/jjs
You actually do have influence over the icon that appears in the dock, via
-Xdock:icon
as described here, if you'd just like a nicer icon to appearRunning that second snippet above, the one with
JFrame
in it, brings to light the second part of why a dock icon remains: due to theAWT-EventQueue-0
thread that is responsible for dispatching GUI events to all the registered event handlers in your program, the JVM does not exit when your program finishes, because only the main thread has exited, and not the GUI ones.The JVM does not know you are finished interacting with it, and thus will wait forever until you either shut down the GUI subsystem or stop the JVM
To solve your "hang" problem, forcefully shutting down the JVM via
System.exit(0)
may work fine for your needs. I would presume thejnius
syntax would be something like:but that syntax is only my speculation, as I don't have
jnius
installed on my system.