import subprocess import time while True: # Get the current time and print it when starting the process restart_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) print(f"Starting worker script at {restart_time}") # Start the worker script in a new Command Prompt window with a custom title process = subprocess.Popen(['start', 'cmd', '/c', 'title TCP_SPLITTER && worker.exe'], shell=True) # Wait a moment to allow the process to start time.sleep(2) while True: # Check if the specific titled process is still running result = subprocess.run('tasklist /v | findstr "TCP_SPLITTER"', shell=True, stdout=subprocess.PIPE, text=True) # If "TCP_SPLITTER" title is not found, the worker script has stopped if "TCP_SPLITTER" not in result.stdout: exit_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) print(f"Worker script exited at {exit_time}. Restarting...") break # Exit the inner loop to restart the outer loop and launch the script again # Check every second if the script is still running time.sleep(1)