Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r60025:509f13a420c6
Date: 2013-01-13 12:20 +0100
http://bitbucket.org/pypy/pypy/changeset/509f13a420c6/

Log:    Don't use finally to call gc_thread_die: the exception has really
        nowhere to go.

diff --git a/pypy/module/thread/os_thread.py b/pypy/module/thread/os_thread.py
--- a/pypy/module/thread/os_thread.py
+++ b/pypy/module/thread/os_thread.py
@@ -2,6 +2,7 @@
 Thread support based on OS-level threads.
 """
 
+import os
 from pypy.module.thread import ll_thread as thread
 from pypy.module.thread.error import wrap_thread_error
 from pypy.interpreter.error import OperationError, operationerrfmt
@@ -91,14 +92,18 @@
         # run!
         try:
             bootstrapper.run(space, w_callable, args)
-        finally:
-            bootstrapper.nbthreads -= 1
-            # clean up space.threadlocals to remove the ExecutionContext
-            # entry corresponding to the current thread
+            # done
+        except Exception, e:
+            # oups! last-level attempt to recover.
             try:
-                space.threadlocals.leave_thread(space)
-            finally:
-                thread.gc_thread_die()
+                STDERR = 2
+                os.write(STDERR, "Thread exited with ")
+                os.write(STDERR, str(e))
+                os.write(STDERR, "\n")
+            except OSError:
+                pass
+        bootstrapper.nbthreads -= 1
+        thread.gc_thread_die()
     bootstrap = staticmethod(bootstrap)
 
     def acquire(space, w_callable, args):
@@ -129,6 +134,9 @@
                 where = 'thread %d started by ' % ident
                 e.write_unraisable(space, where, w_callable)
             e.clear(space)
+        # clean up space.threadlocals to remove the ExecutionContext
+        # entry corresponding to the current thread
+        space.threadlocals.leave_thread(space)
     run = staticmethod(run)
 
 bootstrapper = Bootstrapper()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to