Message310602
Since the issue seems to have been active lately, may I suggest my view on solving it.
One solution that comes to my mind is to keep a weak reference to the file, and to register an atexit function per file (and to unregister it when the file is closed). Example concept-illustrating python code for the _pyio module:
import atexit, weakref
# ...
class TextIOWrapper(TextIOBase):
def __init__(self):
# ...
self._weakclose = operator.methodcaller('close')
atexit.register(self._weakclose, weakref.proxy(self))
# ...
def close(self):
atexit.unregister(self._weakclose)
# and now actually close the file
There is a possibility of a negative impact arising from the use of operator.methodcaller, because it may return something cached in future versions of python. There is also the issue of unregistering an atexit function during atexit processing. But the general idea seems to be simple and worth considering. |
|
Date |
User |
Action |
Args |
2018-01-24 15:38:06 | Arusekk | set | recipients:
+ Arusekk, tim.peters, nascheme, pitrou, vstinner, nikratio, neologix, martin.panter, serhiy.storchaka, xgdomingo, nitishch |
2018-01-24 15:38:06 | Arusekk | set | messageid: <1516808286.55.0.467229070634.issue17852@psf.upfronthosting.co.za> |
2018-01-24 15:38:06 | Arusekk | link | issue17852 messages |
2018-01-24 15:38:06 | Arusekk | create | |
|