silent
This commit is contained in:
+22
-1
@@ -328,6 +328,27 @@ def _run_mini_batch(
|
||||
df = G4System.run_batch(nEvents, particleSpec, minEnergy_GeV, maxEnergy_GeV,"")
|
||||
return df
|
||||
|
||||
def _run_mini_batch_silent(*args, **kwargs):
|
||||
import sys
|
||||
# Redirect stdout and stderr to silence the output
|
||||
devnull = open(os.devnull, 'w')
|
||||
original_stdout = sys.stdout
|
||||
original_stderr = sys.stderr
|
||||
sys.stdout = devnull
|
||||
sys.stderr = devnull
|
||||
|
||||
try:
|
||||
return _run_mini_batch(*args, **kwargs) # Call your actual function
|
||||
except Exception as e:
|
||||
# Restore original stdout and stderr if an exception occurs
|
||||
sys.stdout = original_stdout
|
||||
sys.stderr = original_stderr
|
||||
raise e
|
||||
finally:
|
||||
# Restore original stdout and stderr
|
||||
sys.stdout = original_stdout
|
||||
sys.stderr = original_stderr
|
||||
devnull.close()
|
||||
|
||||
|
||||
def run_batch(
|
||||
@@ -356,7 +377,7 @@ def run_batch(
|
||||
|
||||
#use a multiprocessing pool to run the mini batches in parallel
|
||||
with multiprocessing.Pool(nCores) as pool:
|
||||
dfs = pool.starmap(_run_mini_batch, [(gd, nevents[i], particleSpec, minEnergy_GeV, maxEnergy_GeV, i) for i in range(nCores)])
|
||||
dfs = pool.starmap(_run_mini_batch_silent, [(gd, nevents[i], particleSpec, minEnergy_GeV, maxEnergy_GeV, i) for i in range(nCores)])
|
||||
|
||||
return pd.concat(dfs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user