Time.sleep() not running when terminal closes

def background_scheduler():
    schedule.every(5).seconds.do(job)
    while 1:
        schedule.run_pending()
        time.sleep(1)

I’m currently using the scheduler module for a project I’m working on, It supposed to run in the background and when I exit the terminal and come back it’s running as a process but this bit of code just doesn’t want to run. when I run it in the terminal it runs fine but only when I send it to the background time.sleep refuses to work. any idea why? I also assigned a thread to this function if that matters.

What’s the OS, what are you using to run your script and how are you setting it up to run in the background and ensuring it’s not terminated when your terminal is shut down?

I’m running on ubuntu, here’s what I run:

python3 sms.py &

it runs fine until i close the terminal

It’s fairly standard for *nix based systems to kill the processes you’re running when you close the parent terminal session (it’s worth checking if this has occurred). Have a look at something like nohup which keeps the process running even when the terminal closes though you may want to consider the best way to stop it when you log back in as it wouldn’t be directly listed under jobs any more.

1 Like

It worked Thank you! i credited you in the readme, i was about to give up!