Hi John,

"John Nagle" <na...@animats.com> wrote in message news:4c75768a$0$1608$742ec...@news.sonic.net...
    You don't need a queue, though; just use your own "write" function
with a lock.

Hmm... that would certainly work. I suppose it's even more efficient than a queue in that the first thing the queue is going to do is to acquire a lock; thanks for the idea!

   def atomicwrite(fd, data) :
       with lok :
           fd.write(data)

Cool, I didn't know that threading.Lock() supported "with!" -- Just the other day I was contemplating how one might go about duplicating the pattern in C++ where you do something like this:

   {
Lock lok; // Constructor acquires lock, will be held until destructor called (i.e., while lok remains in scope)
       DoSomething();
   } // Lock released

...clearly "with" does the job here.

---Joel

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to