2

I'm still new to writing scripts with Python and would really appreciate some guidance.

I'm wondering how to continue executing my Python script from where it left off after a system restart.

The script essentially alternates between restarting and executing a task for example: restart the system, open an application and execute a task, restart the system, open another application and execute another task, etc...

But the issue is that once the system restarts and logs back in, all applications shut down including the terminal so the script stops running and never executes the following task. The program shuts down early without an error so the logs are not really of much use. Is there any way to reopen the script and continue from where it left off or prevent applications from being closed during a reboot ? Any guidance on the issue would be appreciated.

Thanks!

Also, I'm using a Mac running High Sierra for reference.

  • Does Apple's `cron` implementation support `@reboot`? – o11c Jun 27 '18 at 06:15
  • 1
    You can run the script as a service which will start automatically when system restart anytime. Check this question https://stackoverflow.com/questions/13069634/python-daemon-and-systemd-service – metmirr Jun 27 '18 at 06:19
  • @metmirr I wonder why you have not written this as an answer instead of writing as comment. – sangharsh Jul 07 '19 at 06:52

1 Answers1

0

You could write your current progress to a file just before you reboot and read said file on Programm start.

About the automatic restart of the script after reboot: you could have the script to put itself in the Autostart of your system and after everything is done remove itself from it.

Teekeks
  • 196
  • 10