This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Arusekk
Recipients Arusekk, martin.panter, nascheme, neologix, nikratio, nitishch, pitrou, serhiy.storchaka, tim.peters, vstinner, xgdomingo
Date 2018-01-24.15:38:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1516808286.55.0.467229070634.issue17852@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-01-24 15:38:06Arusekksetrecipients: + Arusekk, tim.peters, nascheme, pitrou, vstinner, nikratio, neologix, martin.panter, serhiy.storchaka, xgdomingo, nitishch
2018-01-24 15:38:06Arusekksetmessageid: <1516808286.55.0.467229070634.issue17852@psf.upfronthosting.co.za>
2018-01-24 15:38:06Arusekklinkissue17852 messages
2018-01-24 15:38:06Arusekkcreate