473,405 Members | 2,187 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,405 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 3813
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.