alkopop79
Posts: 53
Joined: Thu Mar 08, 2012 7:10 pm
Location: London

Python daemon directory trouble

Mon Nov 20, 2017 9:05 am

I'm trying to create a daemon with Python's daemon library. The code works fine on my desktop machine (Mac OS X), it writes a file in the /tmp directory. On my Pi however it doesn't create a file. Needless to say, I have tried to change the directory to "/home/pi/Templates" and also create a 'tmp' directory in the root directory, with no success. What am I doing wrong?

Code: Select all

import daemon
import time

def do_something():
    while True:
        with open("/tmp/current_time.txt", "w") as f:
            f.write("The time is now " + time.ctime())
        time.sleep(5)

def run():
    with daemon.DaemonContext():
        do_something()

if __name__ == "__main__":
    run()

Return to “Raspbian”

Who is online

Users browsing this forum: No registered users and 17 guests