Cleanup temp files at exit #435

This commit is contained in:
Tomeu Vizoso 2009-02-25 19:28:21 +01:00
parent 29cc73ae18
commit 6508128adc

View File

@ -28,6 +28,8 @@ import binascii
import gettext
import tempfile
import logging
import atexit
import traceback
_ = lambda msg: gettext.dgettext('sugar-toolkit', msg)
@ -291,3 +293,13 @@ class TempFilePath(str):
else:
_tracked_paths[self] -= 1
def _cleanup_temp_files():
logging.debug('_cleanup_temp_files')
for path in _tracked_paths.keys():
try:
os.unlink(path)
except:
logging.error(traceback.format_exc())
atexit.register(_cleanup_temp_files)