Re: [Tutor] Timers in Python

2007-10-16 Thread Trilok Khairnar
Doug Hellmann's PyMotW (Python Module of the Week) series recently covered
sched
http://feeds.feedburner.com/~r/PyMOTW/~3/161303668/pymotw-sched.html

He always provides an overview supported by examples.
You think of a functionality in some context, and it tends to appear in the
series. :-)

Regards,
Trilok.


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Noufal
Ibrahim
Sent: Thursday, October 04, 2007 10:53 PM
To: Kamal
Cc: tutor@python.org
Subject: Re: [Tutor] Timers in Python

Kent Johnson wrote:
 Kamal wrote:
 hello everyone,

 Is there a method in Python which does what
 setInterval('someFunction()',5000) does in Javascript.

 Basically, I want to call functionOne() every x minutes, and
 wondering whats the best way to do it.

You can also look at the sched module that comes with the standard
distribution.




--
~noufal
http://nibrahim.net.in/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Timers in Python

2007-10-15 Thread Kamal
Thanks everyone for the useful feedback.

On 10/4/07, Noufal Ibrahim [EMAIL PROTECTED] wrote:

 Kent Johnson wrote:
  Kamal wrote:
  hello everyone,
 
  Is there a method in Python which does what
  setInterval('someFunction()',5000) does in Javascript.
 
  Basically, I want to call functionOne() every x minutes, and wondering
  whats the best way to do it.

 You can also look at the sched module that comes with the standard
 distribution.




 --
 ~noufal
 http://nibrahim.net.in/
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor




-- 
Thanks,
Kamal
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Timers in Python

2007-10-04 Thread Rob Andrews
On 10/4/07, Kamal [EMAIL PROTECTED] wrote:
 Is there a method in Python which does what
 setInterval('someFunction()',5000) does in Javascript.

 Basically, I want to call functionOne() every x minutes, and wondering
 whats the best way to do it.

Yes, the time module in the standard library has sleep(x), where x is
in seconds.

The Python Library Reference, section 14.2, goes into a bit more detail.

-Rob A.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Timers in Python

2007-10-04 Thread Alan Gauld

Rob Andrews [EMAIL PROTECTED] wrote

 Is there a method in Python which does what
 setInterval('someFunction()',5000) does in Javascript.

 Basically, I want to call functionOne() every x minutes, and 
 wondering
 whats the best way to do it.

 Yes, the time module in the standard library has sleep(x), where x 
 is
 in seconds.

Unfortunately sleep blocks the program so you may need to wrap it
in a thread to launch the required function at the required time
without blocking the main program.

There probably is a third party module that will do this but I don't
know of any.

If its within a GUI context then I think both Tkinter and wxPython
have timer facilities although I've never used them.

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Timers in Python

2007-10-04 Thread Kent Johnson
Alan Gauld wrote:
 If its within a GUI context then I think both Tkinter and wxPython
 have timer facilities although I've never used them.

Tkinter: 
http://www.pythonware.com/library/tkinter/introduction/x9507-alarm-handlers-and-other.htm
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Timers in Python

2007-10-04 Thread Kent Johnson
Kamal wrote:
 hello everyone,
 
 Is there a method in Python which does what
 setInterval('someFunction()',5000) does in Javascript.
 
 Basically, I want to call functionOne() every x minutes, and wondering
 whats the best way to do it.

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65222

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Timers in Python

2007-10-04 Thread Rikard Bosnjakovic
On 04/10/2007, Kamal [EMAIL PROTECTED] wrote:

 Basically, I want to call functionOne() every x minutes, and wondering
 whats the best way to do it.

If you need to run the functions concurrently, use threads. Else you
can setup a simple signal-handler for SIGALRM and set the time
accordingly:


import signal

def setup_signal():
  # Wait 5 seconds before alarming
  signal.alarm(5)
  signal.signal(signal.SIGALRM, signal_handler)

def signal_handler(signum, frame):
  print I got an alarm!

  # need to resetup the signal
  setup_signal()


setup_signal()
# A pointless loop
for x in xrange(5):
  if (x % 10) == 0:
print x



-- 
- Rikard - http://bos.hack.org/cv/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Timers in Python

2007-10-04 Thread Noufal Ibrahim
Kent Johnson wrote:
 Kamal wrote:
 hello everyone,

 Is there a method in Python which does what
 setInterval('someFunction()',5000) does in Javascript.

 Basically, I want to call functionOne() every x minutes, and wondering
 whats the best way to do it.

You can also look at the sched module that comes with the standard 
distribution.




-- 
~noufal
http://nibrahim.net.in/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor