Problems with sockets and threads

Wayne Werner wayne at waynewerner.com
Thu Apr 11 08:27:34 EDT 2013


On Thu, 11 Apr 2013, Dexter Deejay wrote:

> When i try to run this code and to connect to server (server is written in java that part of code is ok) everything stalls. Thread that i created here occupies processor all the time and GUI freezes. It's supposed to be waiting for message from server. (asynchronous one) Is there something that i did wrong here, or is there better way to do this?
>
>
> from tkinter import *
> from threading import *

Everything I've read or used suggests to me that threading+tkinter is a 
dangerous combination.

Mainly because tkinter already has an event loop, so when you start mixing 
threads things tend to go sideways.

Instead what you'll want to do is put processing in the .after or 
.after_idle callbacks - just make sure that whatever is doing is quick (or 
can do a portion of the activity quickly).

HTH,
-W



More information about the Python-list mailing list