diff --git a/.gitignore b/.gitignore index 48ec158cb..355ab7cbd 100644 --- a/.gitignore +++ b/.gitignore @@ -49,4 +49,7 @@ codecov coverage.xml #wandb -wandb/ \ No newline at end of file +wandb/ + +#fcntl +.lock \ No newline at end of file diff --git a/sinergym/config/modeling.py b/sinergym/config/modeling.py index b51e466a3..8f33da3e4 100644 --- a/sinergym/config/modeling.py +++ b/sinergym/config/modeling.py @@ -1,4 +1,5 @@ """Class and utilities for backend modeling in Python with Sinergym (extra params, weather_variability, building model modification and files management)""" +import fcntl import json import os import random @@ -525,14 +526,23 @@ def _set_experiment_working_dir(self, env_name: str) -> str: Returns: str: Experiment path for directory created. """ - # Generate experiment dir path - experiment_path = self._get_working_folder( - directory_path=CWD, - base_name='-%s-res' % - (env_name)) - # Create dir - os.makedirs(experiment_path) - # set path like config attribute + # CRITICAL SECTION for paralell execution + # In order to avoid several folders with the same name + with open(CWD + '/.lock', 'w') as f: + # Exclusive lock + fcntl.flock(f, fcntl.LOCK_EX) + try: + # Generate experiment dir path + experiment_path = self._get_working_folder( + directory_path=CWD, + base_name='-%s-res' % + (env_name)) + # Create dir + os.makedirs(experiment_path) + finally: + # Release lock + fcntl.flock(f, fcntl.LOCK_UN) + # Set path like config attribute self.experiment_path = experiment_path self.logger.info( diff --git a/sinergym/version.txt b/sinergym/version.txt index 7cb75caa9..fbcbf7380 100644 --- a/sinergym/version.txt +++ b/sinergym/version.txt @@ -1 +1 @@ -3.3.8 \ No newline at end of file +3.4.0 \ No newline at end of file