5
5
from time import process_time , time
6
6
7
7
import h5py
8
+ import hdf5plugin
8
9
import numpy as np
9
10
import simplekml
10
11
from multiprocess import Lock , Process , JoinableQueue
@@ -271,7 +272,9 @@ def _run_in_parallel(self, append, light_mode, n_workers=None):
271
272
272
273
with MonteCarloManager () as manager :
273
274
# initialize queue
274
- write_lock = manager .Lock ()
275
+ inputs_lock = manager .Lock ()
276
+ outputs_lock = manager .Lock ()
277
+ errors_lock = manager .Lock ()
275
278
sim_counter = manager .SimCounter ()
276
279
queue = manager .JoinableQueue ()
277
280
@@ -326,7 +329,9 @@ def _run_in_parallel(self, append, light_mode, n_workers=None):
326
329
self .rocket ,
327
330
self .flight ,
328
331
sim_counter ,
329
- write_lock ,
332
+ inputs_lock ,
333
+ outputs_lock ,
334
+ errors_lock ,
330
335
queue ,
331
336
light_mode ,
332
337
file_paths ,
@@ -356,7 +361,9 @@ def _run_simulation_worker(
356
361
sto_rocket ,
357
362
sto_flight ,
358
363
sim_counter ,
359
- write_lock ,
364
+ inputs_lock ,
365
+ outputs_lock ,
366
+ errors_lock ,
360
367
queue ,
361
368
light_mode ,
362
369
file_paths ,
@@ -434,13 +441,15 @@ def _run_simulation_worker(
434
441
}
435
442
436
443
# Write flight setting and results to file
437
- write_lock .acquire ()
444
+ inputs_lock .acquire ()
438
445
with open (file_paths ["input_file" ], mode = 'a' , encoding = "utf-8" ) as f :
439
446
f .write (json .dumps (inputs_dict , cls = RocketPyEncoder ) + "\n " )
447
+ inputs_lock .release ()
448
+
449
+ outputs_lock .acquire ()
440
450
with open (file_paths ["output_file" ], mode = 'a' , encoding = "utf-8" ) as f :
441
451
f .write (json .dumps (results , cls = RocketPyEncoder ) + "\n " )
442
-
443
- write_lock .release ()
452
+ outputs_lock .release ()
444
453
445
454
else :
446
455
input_parameters = flightv1_serializer (
@@ -457,14 +466,15 @@ def _run_simulation_worker(
457
466
str (sim_idx ): flight_results ,
458
467
}
459
468
460
- write_lock .acquire ()
469
+ inputs_lock .acquire ()
461
470
with h5py .File (file_paths ["input_file" ], 'a' ) as h5_file :
462
471
MonteCarlo .dict_to_h5 (h5_file , '/' , export_inputs )
472
+ inputs_lock .release ()
463
473
474
+ outputs_lock .acquire ()
464
475
with h5py .File (file_paths ["output_file" ], 'a' ) as h5_file :
465
476
MonteCarlo .dict_to_h5 (h5_file , '/' , export_outputs )
466
-
467
- write_lock .release ()
477
+ outputs_lock .release ()
468
478
469
479
sim_end = time ()
470
480
@@ -475,10 +485,10 @@ def _run_simulation_worker(
475
485
476
486
except Exception as error :
477
487
print (f"Error on iteration { sim_idx } : { error } " )
478
- write_lock .acquire ()
488
+ errors_lock .acquire ()
479
489
with open (file_paths ["error_file" ], mode = 'a' , encoding = "utf-8" ) as f :
480
490
f .write (json .dumps (inputs_dict , cls = RocketPyEncoder ) + "\n " )
481
- write_lock .release ()
491
+ errors_lock .release ()
482
492
raise error
483
493
484
494
finally :
0 commit comments