Damit du ihn von innen schließen kannst darf er nicht in einem blocking-socket stecken.
Ich habe hier mal meinen code.
Code: Alles auswählen
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind((c['server'],c['port']))
sock.setblocking(0)
sock.listen(c['thread'])
#sock.setblocking(0)
while True:
channel, details = sock.accept()
channel.setblocking(0)
print "OPEN ", details
thread.start_new_thread(handle,(details,))
danke cracki non-blocking sockets sind die Antwort
aus Python Dokumentation Sockets 17.2.1
setblocking( flag)
Set blocking or non-blocking mode of the socket: if flag is 0, the socket is set to non-blocking, else to blocking mode. Initially all sockets are in blocking mode. In non-blocking mode, if a recv() call doesn't find any data, or if a send() call can't immediately dispose of the data, a error exception is raised; in blocking mode, the calls block until they can proceed. s.setblocking(0) is equivalent to s.settimeout(0); s.setblocking(1) is equivalent to s.settimeout(None).
Man kann also immer abfragen ob daten da sind wenn ja kann man sie verarbeiten wenn nein auch egal. Im nächsten schritt kann man prüfen ob man den socket schließen möchte wenn nein gehts wieder von vorne los.