Async Sleep?

A

Aleksandar Cikota

Hi all,

Does a async sleep exist?
How to check this every 10 sec, but that the CPU is free?


Code:
import win32com.client
import time
import os
Document = win32com.client.Dispatch('MaxIm.Document')
Application = win32com.client.dynamic.Dispatch('MaxIm.Application')

path_to_watch = "F:/Images/VRT/"
before = dict ([(f, None) for f in os.listdir (path_to_watch)])

##check this every 10 sec
after = dict ([(f, None) for f in os.listdir (path_to_watch)])
added = [f for f in after if not f in before]
if added:
name= ' ,'.join (added)
print name
if str(name[-3:])=='fit':
Document.OpenFile('F:/Images/VRT/'+name)
Document.SaveFile('F:/Images/VRT/'+ str(name[0:-4])+'.jpeg',
6, False)
Application.CloseAll()

before = after



Tkank You!

Regards,
Aleksandar
 
D

Daniel Nogradi

Hi all,
Does a async sleep exist?
How to check this every 10 sec, but that the CPU is free?

I would use a separate thread for this, perhaps even a completely
detached daemon. You might want to check the docs for threading:

http://docs.python.org/lib/module-threading.html

and these recipes on how to create a daemon:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52216

You can also spawn a separate process with the spawn* family of
functions. If you use them with the os.P_NOWAIT mode, your program
will not hang until the spawned process finishes. See:

http://docs.python.org/lib/os-process.html
 
L

Lawrence D'Oliveiro

"Aleksandar Cikota said:
How to check this every 10 sec, but that the CPU is free?

Or better still, why not set a notification on the directory, so you're
woken up every time something happens to it?

Look up the inotify mechanism, which was added in version 2.6.13 of the
Linux kernel.
 
T

Tim Head

If your task is indeed to watch a directory for "activity" and thenact
upon this activity then you would be much better of doing what Lawrence
suggests. For linux there is the inotify bit in the kernel.
As you are using win32com I'll assume you are using windows.

This snippet in the cookbook seems to do the job
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/156178

if it doesn't do exactly what you wnat have a poke around win32

tim
 

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,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top