Author: Armin Rigo <[email protected]>
Branch: use-gc-del-3
Changeset: r84323:837ed78ee722
Date: 2016-05-09 10:28 +0200
http://bitbucket.org/pypy/pypy/changeset/837ed78ee722/

Log:    Documentation (thanks cfbolz)

diff --git a/pypy/doc/discussion/finalizer-order.rst 
b/pypy/doc/discussion/finalizer-order.rst
--- a/pypy/doc/discussion/finalizer-order.rst
+++ b/pypy/doc/discussion/finalizer-order.rst
@@ -33,26 +33,25 @@
 it from a finalizer.  A finalizer runs earlier, and in topological
 order; care must be taken that the object might still be reachable at
 this point if we're clever enough.  A destructor on the other hand runs
-last; nothing can be done with the object any more.
+last; nothing can be done with the object any more, and the GC frees it
+immediately.
 
 
 Destructors
 -----------
 
 A destructor is an RPython ``__del__()`` method that is called directly
-by the GC when there is no more reference to an object.  Intended for
-objects that just need to free a block of raw memory or close a file.
+by the GC when it is about to free the memory.  Intended for objects
+that just need to free an extra block of raw memory.
 
 There are restrictions on the kind of code you can put in ``__del__()``,
 including all other functions called by it.  These restrictions are
-checked.  In particular you cannot access fields containing GC objects;
-and if you call an external C function, it must be a "safe" function
-(e.g. not releasing the GIL; use ``releasegil=False`` in
-``rffi.llexternal()``).
+checked.  In particular you cannot access fields containing GC objects.
+Right now you can't call any external C function either.
 
-If there are several objects with destructors that die during the same
-GC cycle, they are called in a completely random order --- but that
-should not matter because destructors cannot do much anyway.
+Destructors are called precisely when the GC frees the memory of the
+object.  As long as the object exists (even in some finalizer queue or
+anywhere), its destructor is not called.
 
 
 Register_finalizer
diff --git a/pypy/interpreter/executioncontext.py 
b/pypy/interpreter/executioncontext.py
--- a/pypy/interpreter/executioncontext.py
+++ b/pypy/interpreter/executioncontext.py
@@ -548,11 +548,15 @@
 
     def gc_disabled(self, w_obj):
         # If we're running in 'gc.disable()' mode, record w_obj in the
-        # "call me later" list and return True.  Use this function
-        # from _finalize_() methods that would call app-level some
-        # things that we consider shouldn't be called in gc.disable().
-        # (The exact definition is of course a bit vague, but most
-        # importantly this includes all user-level __del__().)
+        # "call me later" list and return True.  In normal mode, return
+        # False.  Use this function from some _finalize_() methods:
+        # if a _finalize_() method would call some user-defined
+        # app-level function, like a weakref callback, then first do
+        # 'if gc.disabled(self): return'.  Another attempt at
+        # calling _finalize_() will be made after 'gc.enable()'.
+        # (The exact rule for when to use gc_disabled() or not is a bit
+        # vague, but most importantly this includes all user-level
+        # __del__().)
         pdd = self.pending_with_disabled_del
         if pdd is None:
             return False
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to