tkinter, threads and asyncore together

Eric Brunel eric.brunel at N0SP4M.com
Thu Feb 12 08:24:05 EST 2004


Josiah Carlson wrote:
> george.trojan at noaa.gov wrote:
> 
>> My application consists of Tkinter GUI that has to communicate with a
>> remote
>> server. The communication is bi-directional: the GUI responds to remote
>> requests and user actions uch as pressing a button) should send messages
>>
>> to the server. I want to have the network interface implemented as a
>> separate
>> thread, as it may take a while to proccess incoming messages. My initial
>> approach is the following
>>
>>  ------   Queue   --------------------
>> |      | <------ |      asyncore      |        socket
>> | GUI  |    ?    |dispatcher_with_send| <------------------>  server
>> |      | ------> |                    |
>>  ------           --------------------
>>
>> My question is how to communicate with asyncore (to send a message, or
>> end the thread)? I started with creating an additional dispatcher class
>> using unix domain socket, but is seems wrong, why use sockets within the
>> same process? I might try file_dispatcher around a pipe, but maybe I
>> should use different design altogether.
>>
>> George
>>
> 
> #to control asyncore
> while 1:
>     asyncore.loop(.1)
>     if not fromgui.empty():
>         #handle messages from GUI
> 
> Another option is to just have one thread, with the mainloop of Tkinter 
> do a single asyncore.loop(0) call every .01 seconds or so.  In wxPython 
> I'd just use a wxTimer, I don't know if Tkinter has an equivalent.

Yep: use the after method to call a function from the Tkinter main loop after a 
given delay. See 
http://www.pythonware.com/library/tkinter/introduction/x9507-alarm-handlers-and-other.htm

HTH
-- 
- Eric Brunel <eric dot brunel at pragmadev dot com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com




More information about the Python-list mailing list