[pypy-commit] pypy use-gc-del-3: Fix _io
arigo
pypy.commits at gmail.com
Thu May 5 12:15:58 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: use-gc-del-3
Changeset: r84226:bf03d5356e33
Date: 2016-05-05 18:16 +0200
http://bitbucket.org/pypy/pypy/changeset/bf03d5356e33/
Log: Fix _io
diff --git a/pypy/module/_io/interp_bufferedio.py b/pypy/module/_io/interp_bufferedio.py
--- a/pypy/module/_io/interp_bufferedio.py
+++ b/pypy/module/_io/interp_bufferedio.py
@@ -952,9 +952,15 @@
self.w_writer = None
raise
- def __del__(self):
- self.clear_all_weakrefs()
+ def _finalize_(self):
# Don't call the base __del__: do not close the files!
+ # Usually the _finalize_() method is not called at all because
+ # we set 'needs_to_finalize = False' in this class, so
+ # W_IOBase.__init__() won't call register_finalizer().
+ # However, this method might still be called: if the user
+ # makes an app-level subclass and adds a custom __del__.
+ pass
+ needs_to_finalize = False
# forward to reader
for method in ['read', 'peek', 'read1', 'readinto', 'readable']:
diff --git a/pypy/module/_io/interp_iobase.py b/pypy/module/_io/interp_iobase.py
--- a/pypy/module/_io/interp_iobase.py
+++ b/pypy/module/_io/interp_iobase.py
@@ -59,6 +59,8 @@
self.__IOBase_closed = False
if add_to_autoflusher:
get_autoflusher(space).add(self)
+ if self.needs_to_finalize:
+ self.register_finalizer(space)
def getdict(self, space):
return self.w_dict
@@ -71,13 +73,7 @@
return True
return False
- def __del__(self):
- self.clear_all_weakrefs()
- self.enqueue_for_destruction(self.space, W_IOBase.destructor,
- 'internal __del__ of ')
-
- def destructor(self):
- assert isinstance(self, W_IOBase)
+ def _finalize_(self):
space = self.space
w_closed = space.findattr(self, space.wrap('closed'))
try:
@@ -90,6 +86,7 @@
# equally as bad, and potentially more frequent (because of
# shutdown issues).
pass
+ needs_to_finalize = True
def _CLOSED(self):
# Use this macro whenever you want to check the internal `closed`
More information about the pypy-commit
mailing list