469,643 Members | 1,452 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

Async Sleep?

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.Applicatio n')

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
Apr 16 '06 #1
3 2629
> 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/Coo.../Recipe/278731
http://aspn.activestate.com/ASPN/Coo...n/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
Apr 16 '06 #2
In article <e1**********@ss405.t-com.hr>,
"Aleksandar Cikota" <al****@web.de> wrote:
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.
Apr 16 '06 #3
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/Coo.../Recipe/156178

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

tim

Apr 17 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.