Skip to content

Commit

Permalink
Pre-initialise temporary folder instead of lazily
Browse files Browse the repository at this point in the history
This prevents different temporary folders from being created from a single locator object, when the functions are called after multiprocessing creates new processes.
  • Loading branch information
reyery committed Sep 29, 2023
1 parent 078b249 commit 6bd32cb
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions cea/inputlocator.py
Expand Up @@ -34,11 +34,10 @@ def __init__(self, scenario, plugins=None):
self._wrap_locator_methods(plugins)
self.plugins = plugins

self._temp_directory = None
self._temp_directory = tempfile.TemporaryDirectory()

def __del__(self):
if self._temp_directory is not None:
self._temp_directory.cleanup()
self._temp_directory.cleanup()

def __getstate__(self):
"""Make sure we can pickle an InputLocator..."""
Expand Down Expand Up @@ -1115,8 +1114,6 @@ def get_timeseries_plots_file(self, building, category=''):
# OTHER
def get_temporary_folder(self):
"""Temporary folder as returned by `tempfile`."""
if self._temp_directory is None:
self._temp_directory = tempfile.TemporaryDirectory()
return self._temp_directory.name

def get_temporary_file(self, filename):
Expand Down

0 comments on commit 6bd32cb

Please sign in to comment.