Author ncoghlan
Recipients Jurko.Gospodnetić, eric.araujo, georg.brandl, ncoghlan, terry.reedy
Date 2010-12-12.02:22:12
SpamBayes Score 0.0
Marked as misclassified No
Message-id <1292120536.21.0.0775444644537.issue10188@psf.upfronthosting.co.za>
In-reply-to
Content
I have a slightly better fix for that coming soon. There's a subtle race condition in the proposed approach that can lead to the temporary dir not being deleted if an asynchronous exception, such as KeyboardInterrupt, arrives after mkdtemp completes successfully, but before _closed is set back to False.

Instead, the new init code will look like:

        self._closed = False
        self.name = None # Handle mkdtemp throwing an exception
        self.name = mkdtemp(suffix, prefix, dir)

And the cleanup condition will be gated on self.name being set as well as on _closed being False. I believe there is still a window where mkdtemp successfully creates the directory, but self.name never gets set, but we want to make that window as small as possible.

I also realised this should be emitting a ResourceWarning from __del__, as well catching the errors and shut down and turning them into something more meaningful on sys.stderr.

The attached patch won't quite apply cleanly, since it predates r87172
History
Date User Action Args
2010-12-12 02:22:16ncoghlansetrecipients: + ncoghlan, georg.brandl, terry.reedy, eric.araujo, Jurko.Gospodnetić
2010-12-12 02:22:16ncoghlansetmessageid: <1292120536.21.0.0775444644537.issue10188@psf.upfronthosting.co.za>
2010-12-12 02:22:13ncoghlanlinkissue10188 messages
2010-12-12 02:22:13ncoghlancreate