Velocity Reviews - Computer Hardware Reviews

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

Thread Tools

Async Sleep?

Aleksandar Cikota
Posts: n/a
Hi all,

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

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.SaveFile('F:/Images/VRT/'+ str(name[0:-4])+'.jpeg',
6, False)

before = after

Tkank You!


Reply With Quote
Daniel Nogradi
Posts: n/a
> 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:

and these recipes on how to create a daemon:

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:
Reply With Quote
Lawrence D'Oliveiro
Posts: n/a
In article <e1s2h1$m07$(E-Mail Removed)>,
"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
Posts: n/a
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

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


Reply With Quote

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