[Tkinter-discuss] why tkinter hangs on windows with tcl server socket?

Bryan Oakley bryan.oakley at gmail.com
Tue Dec 6 18:09:09 CET 2011


I’m running the following program on Windows, and when I close the app
by clicking on the window manage close button the app hangs. Obviously
this isn’t my real code, but I can’t explain why the code is hanging,
or what the workaround is to get it to not hang.  Interestingly, the
last line of code is executing, so the main loop is terminating but
the python process refuses to die – I’m having to kill it via the task
manager. Even explicitly calling sys.exit() has no effect.

Notice how I create a server socket, then immediately close the
socket. No client is connecting to the server.  It doesn’t matter that
I close it or not, or if I close it after some period of time, it is
the creation of the socket that seems to cause tkinter to hang.

Any ideas?

This is with python 2.7.2.5 from ActiveState, FWIW.

# --- the code ---
import Tkinter as tk

root = tk.Tk()
root.eval('''
    proc Server {args} {puts "Server... $args"}
    set ::the_socket [socket -server Server 0]
    close $::the_socket
''')
root.mainloop()
print "mainloop has exited"
# --- end of the code ---


More information about the Tkinter-discuss mailing list