Queue enhancement suggestion

Jean-Paul Calderone exarkun at divmod.com
Tue Apr 17 10:03:57 EDT 2007


On 17 Apr 2007 13:32:52 GMT, Antoon Pardon <apardon at forel.vub.ac.be> wrote:
>On 2007-04-17, Hendrik van Rooyen <mail at microcorp.co.za> wrote:
> [snip]

>> Not sure I understand this -  it sounds vaguely incestous to me.
>> I normally use a GUI with two queues,  one for input, one for
>> output, to two threads that front end two named pipes to
>> the next process - I try to avoid more than one thing reading or
>> writing to one end of a queue or a pipe, so the dataflow diagram
>> for my stuff always looks like a TinkerToy...
>
>The problem is that sometimes the gui thread has something to show
>too. With the added problem that the code wanting to show something
>doesn't know when it is executing the gui thread or an other. So
>it is very difficult to avoid the gui thread putting things on the
>queue. But since the gui thread is the single reader, it will dead
>lock if the queue happens to be full at the moment the gui thread
>want to add another item.
>

This is pretty easily solved:

    def sendToGUI(event):
        if isInGUIThread():
            gui.scheduleCall(event)
        else:
            guiQueue.put(event)

Jean-Paul



More information about the Python-list mailing list