Async Sleep?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aleksandar Cikota

    #1

    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('MaxI m.Document')
    Application = win32com.client .dynamic.Dispat ch('MaxIm.Appli cation')

    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.OpenFi le('F:/Images/VRT/'+name)
    Document.SaveFi le('F:/Images/VRT/'+ str(name[0:-4])+'.jpeg',
    6, False)
    Application.Clo seAll()

    before = after



    Tkank You!

    Regards,
    Aleksandar


  • Daniel Nogradi

    #2
    Re: Async Sleep?

    > Hi all,[color=blue]
    >
    > Does a async sleep exist?
    > How to check this every 10 sec, but that the CPU is free?[/color]

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

    Source code: Lib/threading.py This module constructs higher-level threading interfaces on top of the lower level_thread module. Availability: not WASI. This module does not work or is not available...


    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:


    Comment

    • Lawrence D'Oliveiro

      #3
      Re: Async Sleep?

      In article <e1s2h1$m07$1@s s405.t-com.hr>,
      "Aleksandar Cikota" <alexci@web.d e> wrote:
      [color=blue]
      >How to check this every 10 sec, but that the CPU is free?[/color]

      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.

      Comment

      • Tim  Head

        #4
        Re: Async Sleep?

        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

        tim

        Comment

        Working...