我有一個從通過套接字在同一網絡上的其它應用程序接收消息並持續運行在等待消息的服務器應用程序。它實際上只是一個觸發器,這似乎工作正常。無法關閉Python應用程序
但我不能關閉應用程序。當我靠近時,GUI凍結,我無法找到解決方案。以下是服務器代碼的相關部分:
class blah blah...
def handler(self, clientsocket, clientaddr):
clientsocket.close()
threading.Thread(target=self.SendFolder).start()
def listen(self):
host = ''
port = 55567
buf = 1024
addr = (host, port)
self.serversocket = socket(AF_INET, SOCK_STREAM)
self.serversocket.bind(addr)
self.serversocket.listen(2)
while 1:
print "Server is listening for connections\n"
clientsocket, clientaddr = self.serversocket.accept()
threading.Thread(target=self.handler, args=(clientsocket, clientaddr)).start()
self.serversocket.close()
def OnClose(self, e):
wx.CallAfter(CloseApp())
class CloseApp(wx.Frame):
def __init__(e):
sys.exit(0)
您正在啓動線程,但在退出前不阻止他們! –
當你需要存在,您將不得不關閉您發表的所有主題... –