Critical sections and mutexes

David Brady daves_spam_dodging_account at
Tue Oct 23 22:54:24 CEST 2001

> -----Original Message-----
> From: Skip Montanaro [mailto:skip at]
> Sent: Tuesday, October 23, 2001 2:04 PM
> Sorry to drop in late on this thread, but why not
> simply make
> PriorityQueue
> a subclass of Queue.Queue (which already does all
> the locking for you)?

Ooooh.  Had I known this existed... *sigh*

Well, now that I've written a priority queue, however,
I'm thinking it does what I need moderately better. 
my queue class has a method Put(self, object,
Priority=0) that puts the object into one of two
internal queues, a priority queue or a normal queue. 
The reason for this is that it could conceivably take
a while (possibly 100ms or more) to process some data
packets, and during high traffic times, packets come
in pretty thick bursts.  During this time, our server
may send out a keepalive (ping) packet that must be
replied to within 1-5 seconds or so to prevent the
connection from being closed by the server.

The idea was to have ping messages go into the
priority queue, so that even if there are 10s worth of
"hard-to-process" packets waiting, the keepalive
message is the next one to be processed.

However, I have implemented PriorityQueue using a pair
of lists internally, and perhaps it would be
faster/better to implement them as Queue.Queue

One question that still has not been answered:
critical sections.  Can they be implemented, or can I
only lock other threads out of a given resource?

P.S. I figured out how to lock a resource in the main

main_mutex = threading.Lock()

creates a mutex in the main thread, and now anyone can
acquire()/release() it as needed.

Thanks again,


David Brady
daves_spam_dodging_account at
I'm feeling very surreal today... or *AM* I?

Do You Yahoo!?
Make a great connection at Yahoo! Personals.

More information about the Python-list mailing list