Removal of extracted archive directory after loading

In the archival.load_archive function, the archive file (if it is not a directory, that is) is extracted to a temporary directory and that directory’s removal is postponed till the interpreter exits (via atexit). This is done because the extracted directory’s contents are used outside this function in some cases. I have a use case where I would like to remove this temporary directory as soon as possible (by the end of load_archive). I have long-running interpreter sessions involving many models being loaded (and used for inference only) and I don’t want such temporary directories to be retained if they are not needed.

Currently, I’m working around this by extracting the archive file myself and then passing in the extracted directory path, calling load_archive with that path, then manually cleaning up. This works, but ideally I would like to be able to call load_archive with an archive file directly and have the temporary directory that it creates removed without postponement.

Does this seem reasonable? I have been crafting a pull request that allows postponement to be turned off. So, everything should work the same after my changes, but one will be able to specify postpone_cleanup=False to get the behavior I’m interested in.

This seems totally reasonable to me. Please submit the PR.

1 Like