1

I am trying to run a Jython script in the background. This is what the script looks like,

a_jython_script.py

for i in range(10000):
    print i

When I try to run it in the background, it is stopped before it prints anything.

 $ jython a_jython_script.py &
[1] 12325
 $

[1]+  Stopped                 jython a_jython_script.py

Sending it to the foreground allows it to continue normally. jython was installed via brew. Taking a look at what the jython startup script is doing, I can just run the Java program and get the same results.

 $ /Library/Java/JavaVirtualMachines/jdk1.8.0_212.jdk/Contents/Home/bin/java -Xmx512m -Xss2560k -classpath ../../../../../../usr/local/Cellar/jython/2.7.1/libexec/jython.jar:. -Dpython.home=../../../../../../usr/local/Cellar/jython/2.7.1/libexec -Dpython.executable=../../../../../../usr/local/Cellar/jython/2.7.1/libexec/bin/jython -Dpython.launcher.uname=darwin -Dpython.launcher.tty=true -Dfile.encoding=UTF-8 org.python.util.jython a_jython_script.py &
[1] 12623
 $

[1]+  Stopped                 /Library/Java/JavaVirtualMachines/jdk1.8.0_212.jdk/Contents/Home/bin/java -Xmx512m -Xss2560k -classpath ../../../../../../usr/local/Cellar/jython/2.7.1/libexec/jython.jar:. -Dpython.home=../../../../../../usr/local/Cellar/jython/2.7.1/libexec -Dpython.executable=../../../../../../usr/local/Cellar/jython/2.7.1/libexec/bin/jython -Dpython.launcher.uname=darwin -Dpython.launcher.tty=true -Dfile.encoding=UTF-8 org.python.util.jython a_jython_script.py
 $

Adding nohup does not make a difference.

Java was installed with the Oracle installer. I see the same behavior in Terminal as well as iTerm2. I do not see the same issue under Linux.

  • What behavior do you expect to see while the script is running in the background? – bmike Jun 19 at 17:48
  • @bmike, printing numbers 0-9999. you can run with python in the background to see expected behavior – Russell Jun 19 at 18:43
0

I got the answer on github: https://github.com/jythontools/jython/issues/148

Solution is summarized below.

when running with jython,

export JAVA_OPTS="-Dpython.launcher.tty=false"
jython a_jython_script.py &

Invoking with java add -Dpython.launcher.tty=false

/Library/Java/JavaVirtualMachines/jdk1.8.0_212.jdk/Contents/Home/bin/java -Xmx512m -Xss2560k -classpath ../../../../../../usr/local/Cellar/jython/2.7.1/libexec/jython.jar:. -Dpython.home=../../../../../../usr/local/Cellar/jython/2.7.1/libexec -Dpython.executable=../../../../../../usr/local/Cellar/jython/2.7.1/libexec/bin/jython -Dpython.launcher.uname=darwin -Dpython.launcher.tty=true -Dfile.encoding=UTF-8 -Dpython.launcher.tty=false org.python.util.jython a_jython_script.py &

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .