Skip to content
Snippets Groups Projects
  • Dimitrios Apostolou's avatar
    1ee33f4e
    tempfiles: clean up temporary directories as you go · 1ee33f4e
    Dimitrios Apostolou authored and Chris Lamb's avatar Chris Lamb committed
    Previously the temporary directories where all left in place until the
    end of the process, when a massive cleanup was being run. The cause
    was the _DIRS variable that was holding references to the
    TemporaryDirectory objects, so their destructor was not running.
    
    We now remove the _DIRS list completely (replacing it with _BASEDIR for
    storing only the parent temporary directory). As a result, the temporary
    directories and their contents are being cleaned up automatically when
    the class destructor runs.
    
    This in turn requires modifications to preexisting code:
    
    1. Code that was directly using `get_temporary_directory().name`
       stopped working; the object from `get_temporary_directory()`
       needs to be referenced directly to keep it alive.
    2. `get_temporary_directory()` is now starting a `with` block
       (context manager) where it was straightforward.
    1ee33f4e
    History
    tempfiles: clean up temporary directories as you go
    Dimitrios Apostolou authored and Chris Lamb's avatar Chris Lamb committed
    Previously the temporary directories where all left in place until the
    end of the process, when a massive cleanup was being run. The cause
    was the _DIRS variable that was holding references to the
    TemporaryDirectory objects, so their destructor was not running.
    
    We now remove the _DIRS list completely (replacing it with _BASEDIR for
    storing only the parent temporary directory). As a result, the temporary
    directories and their contents are being cleaned up automatically when
    the class destructor runs.
    
    This in turn requires modifications to preexisting code:
    
    1. Code that was directly using `get_temporary_directory().name`
       stopped working; the object from `get_temporary_directory()`
       needs to be referenced directly to keep it alive.
    2. `get_temporary_directory()` is now starting a `with` block
       (context manager) where it was straightforward.