Here's a version which generates a tmp dir, and atexit runs cleanup
atexit
cleanup
import atexit import tempfile temp_dir = tempfile.TemporaryDirectory() os.environ["PROMETHEUS_MULTIPROC_DIR"] = temp_dir.name atexit.register(temp_dir.cleanup)