do something every n seconds

S

Santiago Caracol

Hello,

how can I do something (e.g. check if new files are in the working
directory) every n seconds in Python?

Santiago
 
A

Alice Bevan–McGregor

how can I do something (e.g. check if new files are in the working
directory) every n seconds in Python?

The simplest method is executing time.sleep(n) within an infinite while
loop. There are more elegant solutions: using coroutine frameworks,
threaded task schedulers, etc.

— Alice.
 
P

Paul Rubin

Santiago Caracol said:
how can I do something (e.g. check if new files are in the working
directory) every n seconds in Python?

Don't do it that way if you can help it. Use inotify or the equivalent
instead.
 
S

Stefan Sonnenberg-Carstens

Windows or UNIX ?

Am Do, 25.11.2010, 13:38 schrieb Santiago Caracol:
Hello,

how can I do something (e.g. check if new files are in the working
directory) every n seconds in Python?

Santiago


--
MfG,

Stefan Sonnenberg-Carstens

IT Architect
 
S

Steve Holden

Hello,

how can I do something (e.g. check if new files are in the working
directory) every n seconds in Python?
Look at the sched library, which was written to take care of
requirements like this. Use time.sleep() as your delay function and
time.time() as your time function.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top