473,242 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,242 software developers and data experts.

tkinter, threads and asyncore together

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

Jul 18 '05 #1
5 3802
ge***********@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.


I don't know what, if anything, asyncore has for that, but it's
"competition" Twisted has something called callFromThread(). This
method arranges for the specified callable to be called from within
the asynchronous loop at the next opportunity, allowing a separate
thread to communicate back to the objects in the async thread.

Maybe asyncore has something similar? (Checking the docs for it,
I can't see anything that would help.)

-Peter
Jul 18 '05 #2
On Wed, Feb 11, 2004 at 07:11:58PM +0000, ge***********@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.


You need something selectable to wake asyncore up from its call to
select(). The easiest way to do this is with a pipe. You don't have to
send any actual message over the pipe, though; one byte will be enough to
get asyncore to call back into your code, then you can retrieve the message
from wherever it is (eg, in a Queue.Queue).

Jp
Jul 18 '05 #3
ge***********@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.

- Josiah
Jul 18 '05 #4
> #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.


I meant asyncore.poll(.1) and asyncore.poll(0) respectively.

- Josiah
Jul 18 '05 #5
Josiah Carlson wrote:
ge***********@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/tk...-and-other.htm

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

Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michael Schutte | last post by:
I know, questions about Tkinter and threads have been answered very often, but I want to ask anyway. I am using Python 2.2 on a Linux (SuSE Linux 8.1) system. I want to write a server application;...
2
by: duane voth | last post by:
> #to control asyncore > while 1: > asyncore.loop(.1) > if not fromgui.empty(): > #handle messages from GUI The above doesn't work for me - asyncore.loop(<anything>) always...
2
by: Irmen de Jong | last post by:
Hi, I'm having trouble with the code below. It's just a regular Tk text widget in which you can type and select text as expected, however the call to tkFileDialog.askopenfilename() seems to screw...
3
by: Jos | last post by:
Hello. I'm using the asyncore and _chat modules to create a network server. I also have, running in a separate thread(s), a "producer" which needs to "push" data onto the network connection(s)....
6
by: m | last post by:
Hello, I have an application that processes thousands of files each day. The filenames and various related file information is retrieved, related filenames are associate and placed in a linked...
3
by: scorpion53061 | last post by:
In a seperate thread I assign a variable called timeofentry based on the output of the GetDate function on my SQL Server. The idea is to be able to base the time of the users actions outside of the...
2
by: Nathan Pinno | last post by:
Hi, Can anyone tell me if pygame and Tkinter can work together in the same application? I thought I'd better ask before trying it, since both use widgets. Thanks, Nathan Pinno --
2
by: Kevin Walzer | last post by:
I'm trying to decide whether I need threads in my Tkinter application or not. My app is a front end to a command-line tool; it feeds commands to the command-line program, then reads its output and...
1
by: Giampaolo Rodola' | last post by:
Hi there. Just for the heck of it I'd like to write a simple front-end for an asyncore-based server I wrote by using Tkinter. I wrote a simple graphical interface consisting of two buttons: "Start...
1
by: Jonathan Gardner | last post by:
So, I ran into a problem that I would like to write as little code as possible to solve. The problem is that I would like to send out a bunch of HTTP requests simultaneously, using asynchronous...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.