Link to home
Start Free TrialLog in
Avatar of aideb
aideb

asked on

Kill Python script using Cronjob (semi gracefully)

HI,

I am running Python on Ubuntu. I have been running a python script in a console session however I have now created it as a scheduled cron job.

I also want another job scheduled to kill the script however when I use
killl - 9 python3 script.py

I don't get the usual messages logged through Python telling me that the processes have exited

When running in a console session, I would normally kill the script using Ctrl-C. Is there a way in which to do this?
Avatar of Walter Ritzel
Walter Ritzel
Flag of Brazil image

Well you can write a python script that calls the kill command, using the os import.
But, before you even try, can you describe your scenario a little more, so we can help you with the most appropriate design for it?
Avatar of aideb
aideb

ASKER

Ah sorry, my command was wrong

I am running

kill -9 (pidof python3 script.py)

I am not actually using python to kill it....I am using a shell command line
ASKER CERTIFIED SOLUTION
Avatar of clockwatcher
clockwatcher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aideb

ASKER

Fantastic. Thanks!