1

I have created a script that checks if some other script is running

import os
import datetime
import time
from time import ctime

statinfo = os.stat('nemo_logs/nemo_log_file_' + time.strftime('%Y-%m-%d') + '.txt')
for i in range(1):
    first_size = statinfo.st_size
    time.sleep(10)
    if statinfo.st_size > first_size:
        print("SCRIPT IS RUNNING")
    else:
        print("SCRIPT IS NOT RUNNING. TRYING TO KILL THE SCRIPT...")
        os.system("pkill -9 -f selenium_nemo.py")
        print("SCRIPT KILLED. TRYING TO RESTART THE SCRIPT...")
        os.system("python selenium_nemo.py")
        print("SCRIPT STARTED")

If the script logs are increasing then we are OK, but if the script has stuck for some case i want to stop it and restart the script once more. First i kill the script and then i'am executing os.system("python selenium_nemo.py") . The script starts but it runs inside my main script. How i can i start the selenium_nemo.py on another proccess? 'The for loop is for later'

Thanks

Rafael Shkembi
  • 786
  • 6
  • 16

1 Answers1

2

You can use subprocess module for this. Check out this answer for more.

Community
  • 1
  • 1
Rahul
  • 2,580
  • 1
  • 20
  • 24