May-17-2018, 01:48 AM
(May-16-2018, 11:44 AM)snippsat Wrote: I use schedule if shall to this from Python and not using OS schedule.
Example using psutil to scan processes running.
If process is running nothing happens,if not running will start it.
This check is done every 10-sec.
import schedule import time, os import psutil def check_process(): PROCNAME = "notepad.exe" for proc in psutil.process_iter(): if proc.name() == 'notepad.exe': return True else: return False def check_run(): if check_process(): print('Notepad is running') else: print('Notepad in not running') print('Start <notepad.exe>') os.startfile("notepad.exe") schedule.every(.10).minutes.do(check_run) while True: schedule.run_pending() time.sleep(1)Here close Notepad a couple of times,and it will be restart again.
Output:Notepad is running Notepad is running Notepad is running Notepad in not running Start <notepad.exe> Notepad is running Notepad is running Notepad in not running Start <notepad.exe> Notepad is running
Thank you for your answer
But I have another problem that, I cannot calculate exactly time when process success start(sometime it take too long, sometime very fast to start successful). So if I set schedule to check process,It case can happen.
EX: restart_process take 20 minutes, but all script have run about every 10 minutes >> So if process die, It not enough time to start.
How to deal with this case