Skip to content

Commit 022a8df

Browse files
pex_main: always clean up exploded zip when exiting (#142)
If a pex file contains zip-unsafe files or is otherwise told to explode itself when it runs (e.g. via the `PEX_EXPLODE` environment variable), `pex_main` extracts its own contents to a temporary directory. However, it only deletes those files after the entry point script finishes executing provided that the script does not throw an exception. For large pex archives, this can quickly fill up the file system containing the temporary directory. Unconditionally delete the extracted contents of the pex when the entry point script finishes executing. Fixes #131.
1 parent 8c8d11f commit 022a8df

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

tools/please_pex/pex/pex_main.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,12 @@ def _explode_zip():
337337
# that the cache has already been prepared.
338338
lockfile.write("pex unzip completed")
339339
sys.path = [PEX_PATH] + [x for x in sys.path if x != PEX]
340-
yield
341-
if no_cache:
342-
import shutil
343-
shutil.rmtree(basepath)
340+
try:
341+
yield
342+
finally:
343+
if no_cache:
344+
import shutil
345+
shutil.rmtree(basepath)
344346

345347
return _explode_zip
346348

0 commit comments

Comments
 (0)