File tree 1 file changed +15
-22
lines changed
1 file changed +15
-22
lines changed Original file line number Diff line number Diff line change 2
2
import time
3
3
4
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" ] )
5
+ try :
6
+ # Start the child process
7
+ print ( "Starting catflipper-linux..." )
8
+ process = subprocess . Popen ([ "./ catflipper-linux" ] )
9
+ process . wait ( )
10
10
11
- # Wait for the process to finish
12
- process .wait ()
11
+ print ("catflipper-linux crashed. Restarting..." )
12
+ time .sleep (2 )
13
+ run_and_monitor ()
13
14
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
15
+ except KeyboardInterrupt :
16
+ print ("Process monitor interrupted by user." )
17
+ process .terminate () # ensure process cleanup on exit
18
+ except Exception as e :
19
+ print (f"Error occurred: { e } " )
20
+ time .sleep (2 )
21
+ run_and_monitor ()
29
22
30
23
if __name__ == "__main__" :
31
24
run_and_monitor ()
You can’t perform that action at this time.
0 commit comments