我創建一個UDP套接字服務器,並且我想關閉,如果我從客戶端收到關閉消息比我想關閉UDP連接。停止UDP套接字服務器
當我收到消息時,將顯示Begin
,但不會顯示Finished
。我如何退出此線程?
class MyUDPHandler(SocketServer.BaseRequestHandler):
def handle(self):
data = self.request[0].strip()
dic = self.string_XML_to_dic(data)
if(dic['Cmd'] == str(UDPConst().SHUT_DOWN)):
print('Begin')
self.server.shutdown()
print("Finished")
if __name__ == "__main__":
HOST, PORT = "", prop['udpport']
server = SocketServer.UDPServer((HOST, PORT), MyUDPHandler)
server.serve_forever()
http://docs.python.org/library/socketserver.html聲明關閉()「告訴serve_forever()循環停止並等待,直到它」。你等待它執行清理和關閉多久了? – jlafay 2012-02-03 14:09:52