Skip to content

Commit a8ee600

Browse files
authored
Added the first iteration of the script
Nevo couldn't do it himself ffs
1 parent 8cf3437 commit a8ee600

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

CF-Handler.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import subprocess
2+
import time
3+
4+
def run_and_monitor():
5+
while True:
6+
try:
7+
# Start the child process
8+
print("Starting catflipper-linux...")
9+
process = subprocess.Popen(["./catflipper-linux"])
10+
11+
# Wait for the process to finish
12+
process.wait()
13+
14+
# If the process exits, log the exit code
15+
print(f"catflipper-linux exited with code {process.returncode}")
16+
17+
# Restart if the process was terminated or crashed
18+
if process.returncode != 0:
19+
print("catflipper-linux crashed. Restarting...")
20+
time.sleep(2) # optional: add delay before restart
21+
22+
except KeyboardInterrupt:
23+
print("Process monitor interrupted by user.")
24+
process.terminate() # ensure process cleanup on exit
25+
break
26+
except Exception as e:
27+
print(f"Error occurred: {e}")
28+
time.sleep(2) # optional: delay before attempting restart
29+
30+
if __name__ == "__main__":
31+
run_and_monitor()

0 commit comments

Comments
 (0)