[Jython-checkins] jython: Synchonize runClosers in case other files/resources are being

jim.baker jython-checkins at python.org
Sat Jun 28 08:24:36 CEST 2014


http://hg.python.org/jython/rev/b2c87cfba346
changeset:   7336:b2c87cfba346
user:        Jim Baker <jim.baker at rackspace.com>
date:        Sat Jun 28 00:24:27 2014 -0600
summary:
  Synchonize runClosers in case other files/resources are being
opened/closed during shutdown.

Fixes http://bugs.jython.org/issue1747

files:
  src/org/python/core/PySystemState.java |  44 +++++++------
  1 files changed, 23 insertions(+), 21 deletions(-)


diff --git a/src/org/python/core/PySystemState.java b/src/org/python/core/PySystemState.java
--- a/src/org/python/core/PySystemState.java
+++ b/src/org/python/core/PySystemState.java
@@ -1593,7 +1593,7 @@
             }
 
             // Close the listed resources (and clear the list)
-            runClosers(resourceClosers);
+            runClosers();
             resourceClosers.clear();
 
             // XXX Not sure this is ok, but it makes repeat testing possible.
@@ -1601,6 +1601,27 @@
             isCleanup = false;
         }
 
+        private synchronized void runClosers() {
+            // resourceClosers can be null in some strange cases
+            if (resourceClosers != null) {
+            /*
+             * Although a Set, the container iterates in the order closers were added. Make a Deque
+             * of it and deal from the top.
+             */
+                LinkedList<Callable<Void>> rc = new LinkedList<Callable<Void>>(resourceClosers);
+                Iterator<Callable<Void>> iter = rc.descendingIterator();
+
+                while (iter.hasNext()) {
+                    Callable<Void> callable = iter.next();
+                    try {
+                        callable.call();
+                    } catch (Exception e) {
+                        // just continue, nothing we can do
+                    }
+                }
+            }
+        }
+
         // Python scripts expect that files are closed upon an orderly cleanup of the VM.
         private Thread initShutdownCloser() {
             try {
@@ -1617,7 +1638,7 @@
 
         	@Override
             public synchronized void run() {
-                runClosers(resourceClosers);
+                runClosers();
                 resourceClosers.clear();
             }
         }
@@ -1632,26 +1653,7 @@
      *
      * @param resourceClosers to be called in turn
      */
-    private static void runClosers(Set<Callable<Void>> resourceClosers) {
-        // resourceClosers can be null in some strange cases
-        if (resourceClosers != null) {
-            /*
-             * Although a Set, the container iterates in the order closers were added. Make a Deque
-             * of it and deal from the top.
-             */
-            LinkedList<Callable<Void>> rc = new LinkedList<Callable<Void>>(resourceClosers);
-            Iterator<Callable<Void>> iter = rc.descendingIterator();
 
-            while (iter.hasNext()) {
-                Callable<Void> callable = iter.next();
-                try {
-                    callable.call();
-                } catch (Exception e) {
-                    // just continue, nothing we can do
-                }
-            }
-        }
-    }
 }
 
 

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list