-1

Is there a way to make the Python program to run in background when the system boots?

(on windows and linux systems)

jww
  • 97,681
  • 90
  • 411
  • 885
JOKER
  • 35
  • 1
  • 1
  • 9
  • 1
    On what OS? Windows, Linux, MacOS? – James Mchugh Nov 30 '19 at 05:48
  • 1
    win and linux. it would be very helpful :) – JOKER Nov 30 '19 at 05:51
  • I would take a look at systemd services on Linux. You can possibly do the same thing on Windows if you have WSL, but I have not tried it. – James Mchugh Nov 30 '19 at 05:54
  • in Linux you can use cronjobs, in windows powershell or task manager. – devasia2112 Nov 30 '19 at 05:57
  • maybe but i want to do it remotely so it is easy for win 10 but not for linux – JOKER Nov 30 '19 at 05:58
  • 1
    It should be easy to do it remotely for Linux as well assuming you can SSH in and you have `sudo` privileges – James Mchugh Nov 30 '19 at 06:01
  • 1
    does not matter how you want to do it, you can set your user crontab file in a remote machine via ssh. – devasia2112 Nov 30 '19 at 06:01
  • hmm yes i will try it thank you guys – JOKER Nov 30 '19 at 06:02
  • 2
    This question has been asked and answered everywhere. Possible duplicate of [Run Python script at startup in Ubuntu](https://stackoverflow.com/q/24518522/608639), [Run Python Script on OS boot](https://askubuntu.com/q/817011), [How to start a python file while Windows starts?](https://stackoverflow.com/q/4438020/608639), [Run a program at start-up on python in windows](https://stackoverflow.com/q/31130960/608639), etc. – jww Nov 30 '19 at 09:35

4 Answers4

4

You Can Add Your Script In Startup!

Here is For Window 10

1) First Open Your File Explorer!

Then Paste This Address C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp

Here is the ScreenShot!

enter image description here

in that folder paste your script!

Here is another Screenshot!

enter image description here

It Will Automatically Start Your Script When Your System Boot

Another Thing You Can Try Task Scheduler!

For More Details Here is the website that can help you!

https://tunecomp.net/add-program-to-startup-windows-10/

Hamza Lachi
  • 1,046
  • 7
  • 25
1

On linux in a terminal:

crontab -e

then add the following to the file:

@reboot /usr/bin/python3 /path/to/your/python/script.py
Exp
  • 82
  • 5
0

Yes, If your OS is linux then you can try supervisor. Otherwise you can just directly create a service in linux for your python file which you wants to run and then enable it for auto start when system boots up.

Sarvesh
  • 99
  • 5
  • but it becomes difficult to set this up on a host machine which i dont have complete access . – JOKER Nov 30 '19 at 05:57
  • implementing this solution need sudo access of machine, without that you can not achieve this as per my knowledge. – Sarvesh Nov 30 '19 at 06:05
  • yes i will use the ssh shell for this. thanks for the tips tho :) – JOKER Nov 30 '19 at 06:06
0

This solution is specially for linux system

  • Place the script into /etc/rc.local Scripts there run as root when the system starts

Add your script as python /path/to/script.py &

so add python /path/to/script.py & to /etc/rc.local

For More Info Refer this

akash kumar
  • 121
  • 1
  • 6