[pypy-svn] r76841 - in pypy/trunk/pypy: bin interpreter

afa at codespeak.net afa at codespeak.net
Thu Sep 2 18:14:35 CEST 2010


Author: afa
Date: Thu Sep  2 18:14:33 2010
New Revision: 76841

Modified:
   pypy/trunk/pypy/bin/py.py
   pypy/trunk/pypy/interpreter/baseobjspace.py
Log:
issue554 resolved: On exit, the interpreter should wait for non-daemon threads.
Tested on top of bin/py.py


Modified: pypy/trunk/pypy/bin/py.py
==============================================================================
--- pypy/trunk/pypy/bin/py.py	(original)
+++ pypy/trunk/pypy/bin/py.py	Thu Sep  2 18:14:33 2010
@@ -76,6 +76,8 @@
     config.objspace.suggest(allworkingmodules=False)
     if config.objspace.allworkingmodules:
         pypyoption.enable_allworkingmodules(config)
+    if config.objspace.usemodules.thread:
+        config.translation.thread = True
 
     # create the object space
 

Modified: pypy/trunk/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/trunk/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/trunk/pypy/interpreter/baseobjspace.py	Thu Sep  2 18:14:33 2010
@@ -288,6 +288,7 @@
                 self.timer.stop("startup " + modname)
 
     def finish(self):
+        self.wait_for_thread_shutdown()
         w_exitfunc = self.sys.getdictvalue(self, 'exitfunc')
         if w_exitfunc is not None:
             self.call_function(w_exitfunc)
@@ -305,6 +306,23 @@
             for s in self.FrameClass._space_op_types:
                 print s
 
+    def wait_for_thread_shutdown(self):
+        """Wait until threading._shutdown() completes, provided the threading
+        module was imported in the first place.  The shutdown routine will
+        wait until all non-daemon 'threading' threads have completed."""
+        if not self.config.translation.thread:
+            return
+
+        w_modules = self.sys.get('modules')
+        w_mod = self.finditem_str(w_modules, 'threading')
+        if w_mod is None:
+            return
+
+        try:
+            self.call_method(w_mod, "_shutdown")
+        except OperationError, e:
+            e.write_unraisable(self, "threading._shutdown()")
+
     def reportbytecodecounts(self):
         os.write(2, "Starting bytecode report.\n")
         fd = os.open('bytecode.txt', os.O_CREAT|os.O_WRONLY|os.O_TRUNC, 0644)



More information about the Pypy-commit mailing list