[pypy-commit] pypy stacklet: Fix and clean up the __del__ here.

arigo noreply at buildbot.pypy.org
Mon Aug 8 17:08:43 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: stacklet
Changeset: r46369:9897226cd649
Date: 2011-08-08 11:53 +0000
http://bitbucket.org/pypy/pypy/changeset/9897226cd649/

Log:	Fix and clean up the __del__ here.

diff --git a/pypy/module/_stacklet/interp_stacklet.py b/pypy/module/_stacklet/interp_stacklet.py
--- a/pypy/module/_stacklet/interp_stacklet.py
+++ b/pypy/module/_stacklet/interp_stacklet.py
@@ -22,11 +22,6 @@
         self.pending_exception = None
         self.current_stack = StackTreeNode(None)
 
-    def __del__(self):
-        if self.main_stacklet is not None:
-            self.main_stacklet.__del__()
-        StackletThread.__del__(self)
-
     def new_stacklet_object(self, h, in_new_stack):
         # Called when we switched somewhere else.  'h' is the handle of
         # the new stacklet, i.e. what we just switched away from.
diff --git a/pypy/rlib/rstacklet.py b/pypy/rlib/rstacklet.py
--- a/pypy/rlib/rstacklet.py
+++ b/pypy/rlib/rstacklet.py
@@ -9,12 +9,7 @@
         self._thrd = _c.newthread()
         if not self._thrd:
             raise MemoryError
-
-    def __del__(self):
-        thrd = self._thrd
-        if thrd:
-            self._thrd = lltype.nullptr(_c.thread_handle.TO)
-            _c.deletethread(thrd)
+        self._thrd_deleter = StackletThreadDeleter(self._thrd)
 
     def new(self, callback, arg=llmemory.NULL):
         return self._gcrootfinder.new(self._thrd, callback, arg)
@@ -32,6 +27,20 @@
     def get_null_handle(self):
         return self._gcrootfinder.get_null_handle()
 
+
+class StackletThreadDeleter(object):
+    # quick hack: the __del__ is on another object, so that
+    # if the main StackletThread ends up in random circular
+    # references, on pypy deletethread() is only called
+    # when all that circular reference mess is gone.
+    def __init__(self, thrd):
+        self._thrd = thrd
+    def __del__(self):
+        thrd = self._thrd
+        if thrd:
+            self._thrd = lltype.nullptr(_c.thread_handle.TO)
+            _c.deletethread(thrd)
+
 # ____________________________________________________________
 
 def _getgcrootfinder(config):


More information about the pypy-commit mailing list