Search code examples
pythonterminalschedulerjobsshutdown

Stop Advanced Python Scheduler Job After Closing Terminal


Background

I launched several jobs using the Advanced Python Scheduler (APScheduler) using code similar to the one below.

sched = Scheduler()
sched.start()
sched.add_interval_job(function, minutes=1)
sleep(10000)
sched.shutdown()

I did this from the terminal.

python script.py

Problem

I intended for the jobs to be run a large number of times before shutting down. Unfortunately, I accidentally closed the terminal during their sleep stages, before the jobs could be stopped appropriately with sched.shutdown().

I believe the jobs are still running in the background as I have evidence that the function has been applied even after the terminals were closed.

Question

Is there any way to identify which jobs are still running somewhere in the background and shut them down? Thank you in advance!


Solution

  • Find the process id and kill the process using kill <PID>, or simply pkill -f script.py.