wait until change

Peter Hansen peter at engcorp.com
Fri Oct 17 17:45:52 EDT 2003


Matthew Wilson wrote:
> 
> I just took a midterm in my operating systems class, and a big topic was
> "busy waiting" and semaphores.
> 
> And now, today, a real-world example!  Anyway, the time.sleep() method
> is probably good enough, but how would a semaphore solution work in
> python?  A semaphore solution is one where the process that uses the
> updated file is asleep until another process says "Hey! Wake up! I
> updated the file!".  This avoids all those check_for_update() calls
> which bog down the CPU.

In this case, it appears the OP doesn't have the capability of changing
the other application, so what you suggest is out.

Dave's example with WMI uses the *operating system* to essentially
signal semaphore-like that an update has been made.  As I suggested,
it's obviously much more complicated than the simple time.sleep()
plus os.stat() approach, but there are times when it's the right
way to approach this problem.

-Peter




More information about the Python-list mailing list