views:

100

answers:

3

How would you go about a having a function check something every ten minutes? I would like to check a directory for new files every ten minutes. I know python has a time library but can it be used for this?

A: 

time.sleep:

time.sleep(10*60)

you might want to look into cron or Scheduled Tasks services of the OS.

SilentGhost
`sleep` is an awful way to do this; it is inaccurate and inflexible. Depending on the task, an OS scheduler like `cron` would be a great way to go.
Mike Graham
@Mike: and why do you think that this method should be precise?
SilentGhost
+1  A: 

The sched module is worth a look.

Strawberry
How would i use time.sleep in a loop?
Morpheous
@Morpheus: You wouldn't use `time.sleep()` in a loop with `sched`.
S.Lott
A: 

for checking of files, you may want to try pyinotify

that's linux only
SilentGhost