[pypy-svn] r32670 - pypy/dist/pypy/module/_stackless

auc at codespeak.net auc at codespeak.net
Wed Sep 27 18:03:57 CEST 2006


Author: auc
Date: Wed Sep 27 18:03:55 2006
New Revision: 32670

Modified:
   pypy/dist/pypy/module/_stackless/clonable.py
Log:
with this, it is possible to build a pypy where running app-level coroutines cloned from freshly-created ones work


Modified: pypy/dist/pypy/module/_stackless/clonable.py
==============================================================================
--- pypy/dist/pypy/module/_stackless/clonable.py	(original)
+++ pypy/dist/pypy/module/_stackless/clonable.py	Wed Sep 27 18:03:55 2006
@@ -14,7 +14,6 @@
 from pypy.tool import stdlib_opcode as pythonopcode
 
 class ClonableCoroutine(InterpClonableCoroutine):
-    local_pool = None
     #XXX cut'n'pasted from AppCoroutine
     #    so, watch changes in coroutine.py
 
@@ -183,6 +182,25 @@
         self.frame = switch_frame
 
 
+    def w_clone(self):
+        if not we_are_translated():
+            raise NotImplementedError
+        if self.getcurrent() is self:
+            raise RuntimeError("clone() cannot clone the current coroutine; "
+                               "use fork() instead")
+        if self.local_pool is None:   # force it now
+            self.local_pool = gc_swap_pool(gc_swap_pool(None))
+        # cannot gc_clone() directly self, because it is not in its own
+        # local_pool.  Moreover, it has a __del__, which cloning doesn't
+        # support properly at the moment.
+        copy = ClonableCoroutine(self.space)
+        copy.costate = self.costate # or clone thereof
+        #copy = InterpClonableCoroutine(self.costate)
+        copy.parent = self.parent
+        copy.frame, copy.local_pool = gc_clone(self.frame, self.local_pool)
+        return copy
+
+
 def makeStaticMethod(module, classname, funcname):
     space = module.space
     space.appexec(map(space.wrap, (module, classname, funcname)), """
@@ -227,6 +245,7 @@
     __new__ = interp2app(ClonableCoroutine.descr_method__new__.im_func),
     _framestack = GetSetProperty(w_descr__framestack),
     getcurrent = interp2app(ClonableCoroutine.w_getcurrent),
+    clone = interp2app(ClonableCoroutine.w_clone),
     __reduce__   = interp2app(ClonableCoroutine.descr__reduce__,
                               unwrap_spec=['self', ObjSpace]),
     __setstate__ = interp2app(ClonableCoroutine.descr__setstate__,



More information about the Pypy-commit mailing list