asynchronous comunication, wxPython and threads.

Toby Dickenson tdickenson at devmail.geminidataloggers.co.uk
Tue Jun 21 10:30:41 EDT 2005


On Tuesday 21 June 2005 14:22, Zunbeltz Izaola wrote:

> This comunication is done in a new thread not to frezee the GUI.
> The problem is that when "Stop" is done (it kills the thread) some
> confirmation sockets are mixed (are not receibed in the correct order
> although i use tcp).

I guess you are accessing the socket from both your GUI thread and 
communications thread. Dont do that. An action in the GUI thread should 
signal the communictions thread, then the communictions thread talks to the 
socket.

> I have been told not to do comunication in a new thread; instead, I should
> use asyncronus comunication.

Using non-blocking sockets in the GUI thread may cause the opposite problem to 
the one that led you to use threads in the first place: a blocking operation 
in the GUI may freeze the communications. Maybe that isnt a problem for you. 
If it is, I suggest sticking to two threads.

> What module should i use, asyncore, asynchat, twisted,(anohter) 

If you are talking to only one device, then using blocking sockets is a good 
approach. However Ive never written an application like this that didnt need 
to support a second (or third) machine sooner or later, and three 
communictions threads is starting to get ugly. A framework like Twisted will 
let you handle many machines in the one thread, but it still makes sense to 
keep a second one for the GUI.


-- 
Toby Dickenson



More information about the Python-list mailing list