Blocking code

Adam Tauno Williams awilliam at opengroupware.us
Fri Jan 15 14:13:17 EST 2010


On Fri, 2010-01-15 at 10:12 -0800, eric.frederich wrote:
> I am trying to write something that will watch directories without
> poling them.
> This is what FAM is fore.  Gamin is a re-implementation of FAM and it
> has python bindings.
> The problem is that when I call handle_one_event() it blocks until
> there is an event to handle.
> Pressing Ctrl-C does nothing here.
> This seems to be the behavior of FAM so it was re-implemented in
> Gamin.


Hmmm, I don't know if I believe that.

> I looked at another set of bindings for FAM in Java.
> It came with an example that watched a directory for changes.  They
> basically put the code that blocks in another thread and accepted
> input on a second thread waiting for the user to press q and it would
> kill the blocking thread.

You call is probably doing a select(...) on the file handle that FAM (or
whatever) is going to call back on.  You could probably override that
method and add a timeout.  Then do-whatever... wait-and-listen...
do-whatever.  This works very well in many cases, you won't loose
events, they will still be there when you go back to check.

> I don't know how to do something like this in Python, I have never
> used threads and I'm not sure if thats the way to go.

In Python I'd use multiprocessing rather than threads.
<http://docs.python.org/library/multiprocessing.html>



-- 
OpenGroupware developer: awilliam at whitemice.org
<http://whitemiceconsulting.blogspot.com/>
OpenGroupare & Cyrus IMAPd documenation @
<http://docs.opengroupware.org/Members/whitemice/wmogag/file_view>




More information about the Python-list mailing list