File tree 1 file changed +31
-0
lines changed 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
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 ()
You can’t perform that action at this time.
0 commit comments