changeset 8314:069db4761b37

Allow other threads to complete after main exits (fixes #2836). We leave exiting to the JVM when a main Python program was run and ended with good status.
author Jeff Allen <ja.py@farowl.co.uk>
date Sun, 22 Dec 2019 16:33:35 +0000
parents 3e46a80390fb
children 7fe475b0fea2
files NEWS src/org/python/util/jython.java
diffstat 2 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ https://github.com/jythontools/jython
 Jython 2.7.2b3
   Bugs fixed
     - [ 2820 ] Import fails with UnicodeDecodeError if sys.path contains invalid UTF-8 bytes
+    - [ 2836 ] Java Swing library works only in interactive jython session
 
 Jython 2.7.2b2
   Bugs fixed
--- a/src/org/python/util/jython.java
+++ b/src/org/python/util/jython.java
@@ -674,9 +674,16 @@ public class jython {
             }
         }
 
-        // Shut down in a tidy way
-        interp.cleanup();
-        exit(sts);
+        /*
+         * If we arrive here then we ran some Python code. It is possible that threads we started
+         * are still running, so if the status is currently good, just return into the JVM. (This
+         * exits with good status if nothing goes wrong subsequently.)
+         */
+        if (sts != Status.OK) {
+            // Something went wrong running Python code: shut down in a tidy way.
+            interp.cleanup();
+            exit(sts);
+        }
     }
 
     /**