@@ -112,6 +112,11 @@ def get_benchmark_samples(root_dir: str, config_file="config.yml"):
112112 return list (config ["benchmark_samples" ].keys ())
113113
114114
115+ def touch (path ):
116+ with open (path , 'a' ):
117+ os .utime (path , None )
118+
119+
115120def run_benchmark (root_dir : str , sample : str , config_file = "config.yml" ):
116121 config_file = os .path .join (root_dir , config_file )
117122 with open (config_file , mode = "r" ) as f :
@@ -123,6 +128,21 @@ def run_benchmark(root_dir: str, sample: str, config_file="config.yml"):
123128
124129 working_dir = os .path .join (root_dir , sample_config ["working_dir" ])
125130
131+ # working space locking
132+ if os .path .exists (os .path .join (working_dir , "ready" )):
133+ print ("benchmark sample '%s' was already estimated" % sample )
134+ return
135+ if os .path .exists (os .path .join (working_dir , "lock" )):
136+ print ((
137+ "benchmark sample '%s' is locked. " +
138+ "Maybe there is already another instance estimating this sample?"
139+ ) % sample )
140+ return
141+
142+ print ("locking dir..." , end = "" , flush = True )
143+ touch (os .path .join (working_dir , "lock" ))
144+ print ("\t [OK]" )
145+
126146 print ("loading data..." , end = "" , flush = True )
127147 sim = Simulator ()
128148 sim .load (sim_data_file )
@@ -141,3 +161,8 @@ def run_benchmark(root_dir: str, sample: str, config_file="config.yml"):
141161 estimator .initialize (** init_args )
142162 estimator .train (** training_args )
143163 print ("estimation of benchmark sample '%s' ready" % sample )
164+
165+ print ("unlocking dir and finalizing..." , end = "" , flush = True )
166+ os .remove (os .path .join (working_dir , "lock" ))
167+ touch (os .path .join (working_dir , "ready" ))
168+ print ("\t [OK]" )
0 commit comments