@@ -298,8 +298,7 @@ def __run_in_parallel(self, n_workers=None):
298
298
None
299
299
"""
300
300
if n_workers is None or n_workers > os .cpu_count ():
301
- # For Windows, the number of workers must be at most os.cpu_count() - 1
302
- n_workers = os .cpu_count () - 1
301
+ n_workers = os .cpu_count ()
303
302
304
303
if n_workers < 2 :
305
304
raise ValueError ("Number of workers must be at least 2 for parallel mode." )
@@ -321,6 +320,13 @@ def __run_in_parallel(self, n_workers=None):
321
320
processes = []
322
321
seeds = np .random .SeedSequence ().spawn (n_workers - 1 )
323
322
323
+ sim_consumer = multiprocess .Process (
324
+ target = self .__sim_consumer ,
325
+ args = (export_queue , mutex , consumer_stop_event , simulation_error_event ),
326
+ )
327
+
328
+ sim_consumer .start ()
329
+
324
330
for seed in seeds :
325
331
sim_producer = multiprocess .Process (
326
332
target = self .__sim_producer ,
@@ -337,13 +343,6 @@ def __run_in_parallel(self, n_workers=None):
337
343
for sim_producer in processes :
338
344
sim_producer .start ()
339
345
340
- sim_consumer = multiprocess .Process (
341
- target = self .__sim_consumer ,
342
- args = (export_queue , mutex , consumer_stop_event , simulation_error_event ),
343
- )
344
-
345
- sim_consumer .start ()
346
-
347
346
try :
348
347
for sim_producer in processes :
349
348
sim_producer .join ()
@@ -455,14 +454,18 @@ def __sim_consumer(
455
454
The event indicating that an error occurred during the simulation.
456
455
"""
457
456
trials = 0
458
- while not stop_event .is_set () and not error_event .is_set ():
457
+
458
+ while not error_event .is_set ():
459
459
try :
460
460
mutex .acquire ()
461
461
inputs_dict , outputs_dict = export_queue .get (timeout = 3 )
462
462
463
463
self .__export_flight_data (inputs_dict , outputs_dict )
464
464
465
465
except queue .Empty as exc :
466
+ if stop_event .is_set ():
467
+ break
468
+
466
469
trials += 1
467
470
468
471
if trials > 10 :
0 commit comments