Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python daemon shows no output for an error

I read How do you create a daemon in Python? and also this topic, and tried to write a very simple daemon :

import daemon
import time
with daemon.DaemonContext():
    while True:
        with open('a.txt', 'a') as f:
            f.write('Hi')
        time.sleep(2)

Doing python script.py works and returns immediately to terminal (that's the expected behaviour). But a.txt is never written and I don't get any error message. What's wrong with this simple daemon?

like image 322
Basj Avatar asked Jun 25 '26 00:06

Basj


1 Answers

daemon.DaemonContext() has option working_directory that has default fault value / i.e. your program probably doesn't have permission to create a new file there.

like image 59
J.J. Hakala Avatar answered Jun 27 '26 13:06

J.J. Hakala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!