Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Async Sleep?

Reply
Thread Tools

Async Sleep?

 
 
Aleksandar Cikota
Guest
Posts: n/a
 
      04-16-2006
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


 
Reply With Quote
 
 
 
 
Daniel Nogradi
Guest
Posts: n/a
 
      04-16-2006
> 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
 
Reply With Quote
 
 
 
 
Lawrence D'Oliveiro
Guest
Posts: n/a
 
      04-16-2006
In article <e1s2h1$m07$(E-Mail Removed)-com.hr>,
"Aleksandar Cikota" <(E-Mail Removed)> 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.
 
Reply With Quote
 
Tim Head
Guest
Posts: n/a
 
      04-17-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie: async mode dedicated versus async mode interactive!! Pink_Floyd Cisco 4 06-16-2006 12:16 AM
Async webservice call in async webpage (.Net 2.0) does not return Steven ASP .Net Web Services 0 11-30-2005 01:06 AM
Call for Papers: ASYNC-2005 (New York City) Montek Singh VHDL 0 07-29-2004 05:23 PM
Using a BlockRam in an async FIFO for bus width conversion ? Arnaud VHDL 3 06-28-2004 04:33 PM
[Q] : async event counter dong seok huh VHDL 6 10-06-2003 11:04 AM



Advertisments