1

I want to repeat a function every x seconds when the code its working like deamon in Python 2.6 for Linux. I have some code but its giving me a lot of problems. Is it possible to call a another file.py instead to write the code inside?

Here is the code:

import daemon   
import threading

def hello():
    print "hello, world"
    t = threading.Timer(2.0, hello).start()

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

if __name__ == "__main__":
    run()
1

3 Answers 3

3

Sometimes it isn't worth working through the daemon-specific details. Have a look at supervisord, a process control system that makes it easy to wrap daemonic behaviors around existing applications.

2

What's wrong with:

import daemon   
import threading
import another_file

def problematic_func_loop():
    another_file.peoblematic_func()
    t = threading.Timer(60.0, problematic_func_loop).start()

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

if __name__ == "__main__":
    run()
2
  • i've tried the code above but i got AttributeError: 'module' object has no attribute 'DaemonContext'
    – Jacer Omri
    May 30, 2014 at 19:49
  • i figured it out, it was a versioning issue, the daemon package in pypi was 1.5.5 which has DaemonContext, the version installed with pip command was 1.0, which hasn't.
    – Jacer Omri
    May 30, 2014 at 20:18
0

Take a look at the Fat Controller which can repeat any program every x seconds. It can also handle failures and offer strategies for parallel execution if needed and also the ability to run as a daemon.

There's documentation, examples and use cases at the official website:

http://fat-controller.sourceforge.net/

Not the answer you're looking for? Browse other questions tagged or ask your own question.