wxPython and threads
nick at craig-wood.com
Thu Jul 19 20:30:04 CEST 2007
Josiah Carlson <josiah.carlson at sbcglobal.net> wrote:
> Nick Craig-Wood wrote:
> > I'd dispute that. If you are communicating between threads use a
> > Queue and you will save yourself thread heartache. Queue has a non
> > blocking read interface Queue.get_nowait().
> If you have one producer and one consumer, and the consumer will be
> notified when there is an item available, AND deques (in Python 2.4,
> 2.5, and presumably later) are threadsafe, then the *additional*
> locking, blocking, etc., that a Queue provides isn't necessary.
> Whether one wants to use a Queue for 'piece of mind', or for future
> expansion possibilities is another discussion entirely, but his
> application (as stated) will work with a deque for the worker thread ->
> GUI thread communication path.
You are right deque's do say they are thread safe - I didn't know
that. From the docs :-
Deques support thread-safe, memory efficient appends and pops from
either side of the deque with approximately the same O(1) performance
in either direction.
I think I'd go for the peace of mind option, but YMMV of course ;-)
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick
More information about the Python-list