Skip to content
Snippets Groups Projects
Commit 5a252097 authored by Michael Reuscher's avatar Michael Reuscher
Browse files

new handler for errors an interrupts

parent d7884815
No related branches found
No related tags found
1 merge request!4Python driver and data analysis part
......@@ -4,10 +4,10 @@ import json
import os
# List of byte sizes for the events little one for testing
BYTE_SIZES = ['16', '32', '64', '128', '256', '512', '1024', '2048', '4096', '8192',
'16384', '32768', '65536', '131072', '262144', '524288', '1048576', '2097152',
'4194304', '8388608', '16777216', '33554432', '67108864']
#BYTE_SIZES = ['16', '32', '64', '128']
#BYTE_SIZES = ['16', '32', '64', '128', '256', '512', '1024', '2048', '4096', '8192',
#'16384', '32768', '65536', '131072', '262144', '524288', '1048576', '2097152',
#'4194304', '8388608', '16777216', '33554432', '67108864']
BYTE_SIZES = ['16', '32']
# Function to parse command-line arguments
......@@ -26,7 +26,7 @@ def parse_arguments():
help='Choose function to execute default: various')
parser.add_argument('-d', '--data', type=str, default=main_directory,
help='Folder to store the date for visualizer default: ./')
parser.add_argument('-p', '--protokoll', type=str, default=main_directory,
parser.add_argument('-p', '--testData', type=str, default=main_directory,
help='Folder to store the test data from detector sim default: ./')
return parser.parse_args()
......
......@@ -12,7 +12,7 @@
"note": "this is only a help an it is never used by the simrunner programm",
"--burstInterval": "event interval in a burst default: 1000000",
"--burstLength": "number of events in a burst default: 0",
"-d, --dataGenerator": "name of the data generator default: random",
"--dataGenerator": "name of the data generator default: random",
"--debugOptions": "give debug output to option parsing default: false",
"-h, --help": "give this help default: false",
"-i, --interval": "event interval default: 1000000000",
......@@ -20,7 +20,7 @@
"--noCfgFileRecursion": "do not read config files recursively, must be set before use default: false",
"--noCfgFiles": "do not read the default config files, must be FIRST option default: false",
"--nodeId": "nodeId for object indentification default:",
"-p, --prefixData": "data prepended to output lines default:",
"--prefixData": "data prepended to output lines default:",
"-s, --size": "block size (only needed by long)",
"--skew": "timing skew between threads, fracton of interval default: 0",
"--startTime": "time point to start generating data default: -9223372036.854776",
......
import os
import time
import signal
import subprocess
import logging
import concurrent.futures as cf
......@@ -10,14 +11,19 @@ import config_processing as con
# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
stop_requested = False
# Function to print terminal output and handle errors
def terminal_output(output, errors, return_code):
logger.info(output)
logger.info(errors)
if return_code > 0:
logger.info(f'return code: {return_code}')
logger.error(f'return code: {return_code}')
if errors:
logger.error(errors)
if output:
logger.info(output)
else:
logger.info(output)
# Function to pull data from remote machines to the local machine
......@@ -33,17 +39,35 @@ def rm_data(t_data_path):
if args.hosts:
host = args.hosts[0]
ssh_target = f'{args.user}@{host}'
rm_cmd = f'ssh {ssh_target} rm -f {t_data_path}/*'
rm_cmd = f'ssh {ssh_target} rm -r {t_data_path}'
subprocess.run(rm_cmd, shell=True, check=True)
def handle_sigint(signum, frame):
logger.info("Main process received KeyboardInterrupt")
global stop_requested
stop_requested = True
for h in args.hosts:
kill_target = f'{args.user}@{h}'
kill_cmd = f"ssh {kill_target} pkill -f {args.sim}"
re = subprocess.run(kill_cmd, shell=True)
ou = re.stdout
er = re.stderr
logger.info(f'{ou} {er}')
logger.info(f'{kill_target} killed')
# Function to run the detector simulation with the given event arguments
def run_sim(e_dict, d_path, sim_path, main_path):
with cf.ThreadPoolExecutor() as executor:
signal.signal(signal.SIGINT, handle_sigint)
for event in e_dict:
if stop_requested:
break
futures = []
folder_name = e_dict[event]['-o']
e_dict[event]['--startTime'] = f'@{int(time.time() + 10)}'
e_dict[event]['--posixDataDir'] = os.path.join(e_dict[event]['--posixDataDir'], event)
output_path = os.path.join(d_path, folder_name)
if args and args.hosts:
# Remote execution on multiple machines with specified user
......@@ -60,13 +84,13 @@ def run_sim(e_dict, d_path, sim_path, main_path):
for folder_name, host, future in futures:
output, errors, result = future.result()
terminal_output(output, errors, result)
if host:
stat_file_name = f'statistics_{folder_name}_{host}'
else:
stat_file_name = f'statistics_{folder_name}_lokal'
op.write_statistics(main_path, stat_file_name, output)
if output:
if host:
stat_file_name = f'statistics_{folder_name}_{host}'
else:
stat_file_name = f'statistics_{folder_name}_lokal'
op.write_statistics(main_path, stat_file_name, output)
logger.info(f'{folder_name}_{host if host else ""} done!')
rm_data(test_data_path)
# --- MAIN ---
......@@ -81,11 +105,14 @@ if __name__ == '__main__':
test_data_path = os.path.join(args.data, 'test_data')
# Setup arguments for Sim
#event_dict = con.create_event_list(args, test_data_path)
event_dict = con.create_event_list(args, test_data_path)
# Run detectorSimulation
#run_sim(event_dict, data_path, simulation_path, main_folder_path)
run_sim(event_dict, data_path, simulation_path, main_folder_path)
pull_data(data_path, main_folder_path)
rm_data(test_data_path)
import subprocess
import output_processing as op
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment