我的请求是超过2分钟后关闭主线程。我叫做serve_forever(),但不知道如何关闭主线程。我的代码:
import SocketServer,socket
import threading,time,re
last_request_time = 0
class ThreadSocketServer(SocketServer.ThreadingMixIn,SocketServer.TCPServer):pass
class RequestHandler(SocketServer.BaseRequestHandler):
def handle(self):
global last_request_time
last_request_time = time.time()
# print last_request_time
intact_data = []
while True:
data = str(self.request.recv(1024))
intact_data.append(data)
# if response[-16:-1].find('clientcomplete'):
if re.search('clientcomplete', data):
print 'server recv complete'
self.request.send('Finished')
break
self.request.close()
if __name__ == '__main__':
server = ThreadSocketServer(('192.168.3.33',12345),RequestHandler)
# server.handle_request()
server.serve_forever()
我尝试过server.handle_request(),但它似乎不支持多线程。