Async Sleep?

Discussion in 'Python' started by Aleksandar Cikota, Apr 16, 2006.

  1. 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
     
    Aleksandar Cikota, Apr 16, 2006
    #1
    1. Advertising

  2. > 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
     
    Daniel Nogradi, Apr 16, 2006
    #2
    1. Advertising

  3. In article <e1s2h1$m07$-com.hr>,
    "Aleksandar Cikota" <> 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.
     
    Lawrence D'Oliveiro, Apr 17, 2006
    #3
  4. Aleksandar Cikota

    Tim Head Guest

    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
     
    Tim Head, Apr 17, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Meir Rotfleisch
    Replies:
    1
    Views:
    406
    Rocky Moore
    Nov 14, 2003
  2. Gonzalo Moreno
    Replies:
    2
    Views:
    12,515
  3. Steven
    Replies:
    0
    Views:
    393
    Steven
    Nov 30, 2005
  4. Sam Roberts
    Replies:
    16
    Views:
    402
    Daniel Berger
    Feb 18, 2005
  5. Richard
    Replies:
    7
    Views:
    253
    Richard
    May 22, 2007
Loading...

Share This Page