473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Activate a daemon several times a day

Hi,

I have a daemon which runs permanently, and I want it to do a special
operation at some specifiy times every day, consider this configfile
extract:

[general]
runat=10:00,12:00
What would be the easiest and most pythonic way to do this?
Something like this pseudocode:

while True:
if now(hours) in runat:
act()
sleep(60)
sleep(10)
Please enlighten me!

Best regards,
Yves
Jul 6 '06 #1
2 1344
Yves Glodt wrote:
Hi,

I have a daemon which runs permanently, and I want it to do a special
operation at some specifiy times every day, consider this configfile
extract:

[general]
runat=10:00,12:00
What would be the easiest and most pythonic way to do this?
Something like this pseudocode:

while True:
if now(hours) in runat:
act()
sleep(60)
sleep(10)
Please enlighten me!

Best regards,
Yves
If you're on a unix-ish system, you might consider making your daemon
sensitive to a signal and then use cron and kill to send it that signal
when you want it to activate. This is just an idea. It might not be
the kind of solution you're looking for, especially if you're not
already familiar with cron & crontab.
It might be more helpful to you to tell you that you can get the
current hour as an int using the gmtime() (for UTC) or localtime()
(for, uh, local time :-) ) from the time module:
>>from time import gmtime, localtime
gmtime()
(2006, 7, 6, 16, 6, 32, 3, 187, 0)
>>gmtime()[3]
16
>>help(gmtime)
Help on built-in function gmtime in module time:

gmtime(...)
gmtime([seconds]) -(tm_year, tm_mon, tm_day, tm_hour, tm_min,
tm_sec, tm_wday, tm_yday, tm_isdst)

Convert seconds since the Epoch to a time tuple expressing UTC
(a.k.a.
GMT). When 'seconds' is not passed in, convert the current time
instead.
>>help(localtime)
Help on built-in function localtime in module time:

localtime(...)
localtime([seconds]) ->
(tm_year,tm_mon,tm_day,tm_hour,tm_min,tm_sec,tm_wd ay,tm_yday,tm_isdst)

Convert seconds since the Epoch to a time tuple expressing local
time.
When 'seconds' is not passed in, convert the current time instead.


That takes care of the "now(hours)" part of your pseudocode.
HTH,
~Simon

Jul 6 '06 #2

Yves Glodt wrote:
while True:
if now(hours) in runat:
act()
sleep(60)
sleep(10)
Note that, if "now(hours)" *is* in runat, this loop will sleep 70
seconds, not 60. It probably doesn't matter.

Jul 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rob Hunter | last post by:
Hi all. I want to run a Python daemon that manages a "to-do" queue. I want it so that the daemon is always running, where its running consists of looking at the queue to see if it has any jobs,...
3
by: bmgx | last post by:
This is what I am trying to find out, instruction on how to create a simple daemon on unix systems(Linux), can't find any info on usual sources..
1
by: Bob Swerdlow | last post by:
I've created a Python daemon that starts a bunch of BitTorrent downloader process. Everything is working fine when I start the daemon by hand (logged on as root). I can quit the session and see...
7
by: Michael Ransburg | last post by:
Hi! I have implemented a daemon in C++. It runs all the time, between reboots. Is there a way for other C++ classes to get a reference to the instance of this daemon class in order to call its...
1
by: Stefan Neumann | last post by:
I have written a daemon which should run endlessly. The structure looks like this: - start-stop-daemon forks my python program then: if __name__=="__main__": try: main()
2
by: Reid Priedhorsky | last post by:
Hi folks, I am implementing a forking SocketServer daemon that maintains significant internal state (a graph that takes ~30s to build by fetching from a SQL database, and eventually further...
3
by: paul | last post by:
I am writing a daemon process that reads data from the serial port / dev/ttyS0. I am using pyserial & the method for setting up a daemon described in "Chris' Python Page"...
6
by: Johny | last post by:
Is it possible to run a Python program as daemon? Thanks
13
dmjpro
by: dmjpro | last post by:
class MainClass{ public static void main(String a){ //do something } } When i run this class file then JVM is the process having one main thread. Thread ends and process ends. I went...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.