Zizico2
Posts: 11
Joined: Sun Nov 18, 2018 11:11 pm

Solved: Run Pythom Script as a daemon

Wed Nov 21, 2018 4:01 am

Hi guys I've got a script that defines some event triggered functions. I would like it to always be running in the background.
I'm thinking of putting an infinite loop (While(True):
Pass)
at the end and running it on startup (running it on bootlocal.sh).
Will this work? And is there any better way?
Thanks in advance!
Last edited by Zizico2 on Wed Nov 21, 2018 11:09 am, edited 1 time in total.

PhatFil
Posts: 1543
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Run Pythom Script as a daemon

Wed Nov 21, 2018 4:22 am

afaik there are 2 prefered methods you could use (google)
1) systemd https://www.raspberrypi.org/documentati ... systemd.md
and
2) rc.local https://www.raspberrypi.org/documentati ... c-local.md

Zizico2
Posts: 11
Joined: Sun Nov 18, 2018 11:11 pm

Re: Run Pythom Script as a daemon

Wed Nov 21, 2018 5:44 am

PhatFil wrote:
Wed Nov 21, 2018 4:22 am
afaik there are 2 prefered methods you could use (google)
1) systemd https://www.raspberrypi.org/documentati ... systemd.md
and
2) rc.local https://www.raspberrypi.org/documentati ... c-local.md
Will this work without a loop at the end? Won't the script just end?

PhatFil
Posts: 1543
Joined: Thu Apr 13, 2017 3:55 pm
Location: Oxford UK

Re: Run Pythom Script as a daemon

Wed Nov 21, 2018 6:08 am

yes you will need an endless loop to encapsulate the monitoring code

Zizico2
Posts: 11
Joined: Sun Nov 18, 2018 11:11 pm

Re: Run Pythom Script as a daemon

Wed Nov 21, 2018 11:03 am

PhatFil wrote:
Wed Nov 21, 2018 6:08 am
yes you will need an endless loop to encapsulate the monitoring code
Noob Python question: will event triggered functions get triggered during time.sleep()?

Return to “General discussion”