我有简单的python服务器和客户端.
服务器:
import SocketServer
import threading
class MyTCPHandler(SocketServer.BaseRequestHandler):
def handle(self):
self.data = self.request.recv(1024).strip()
print str(self.client_address[0]) + " wrote: "
print self.data
self.request.send(self.data.upper())
if __name__ == "__main__":
HOST, PORT = "localhost", 3288
server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
server.serve_forever()
Run Code Online (Sandbox Code Playgroud)
客户:
import socket
import sys
from time import sleep
HOST, PORT = "localhost", 3288
data = "hello"
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect((HOST, PORT))
sock.send(data + "\n")
received = sock.recv(1024)
sleep(10)
sock.send(data + "\n")
received = sock.recv(1024)
sleep(10)
sock.send(data + "\n")
received = …Run Code Online (Sandbox Code Playgroud) 根据要求重新打开这个问题(错误:[Errno 10053]),提供最小的可测试示例:
import time
from flask import Flask, render_template
app = Flask(__name__, static_folder='static', template_folder='templates')
@app.route('/')
def main():
return render_template('test.html')
@app.route('/test')
def test():
print "Sleeping. Hit Stop button in browser now"
time.sleep(10)
print "Woke up. You should see a stack trace from the problematic exception below."
return render_template('test.html')
if __name__ == '__main__':
app.run()
Run Code Online (Sandbox Code Playgroud)
HTML:
<html>
<body>
<a href="/test">test</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
指南:运行应用程序,导航到localhost:port,单击链接,然后在浏览器中单击"停止"按钮.一旦睡眠结束,你应该看到异常.睡眠是模拟服务器上发生的任何类型活动所必需的.它可能只是几秒钟:如果用户设法离开页面 - Flask将崩溃.
socket.error:[Errno 10053]已建立的连接已被主机中的软件中止
为什么服务器停止为应用程序提供服务?我可以将哪些其他服务器用于我的Flask应用程序以避免这种情况?