I need to work this script in background like daemon, till now i just could it make work but not in background:
import threading
from time import gmtime, strftime
import time
def write_it():
#this function write the actual time every 2 seconds in a file
threading.Timer(2.0, write_it).start()
f = open("file.txt", "a")
hora = strftime("%Y-%m-%d %H:%M:%S", gmtime())
#print hora
f.write(hora+"\n")
f.close()
def non_daemon():
time.sleep(5)
#print 'Test non-daemon'
write_it()
t = threading.Thread(name='non-daemon', target=non_daemon)
t.start()
I already tried another ways but no of them work in background as I was looking, any other alternative?