Debian で Python (2.7.13) HTTP サーバーを実行しています。10 秒以上かかる GET リクエストを停止したいのですが、どこにも解決策が見つかりません。
次の質問に投稿されたすべてのスニペットを既に試しました: BaseHTTPServer.BaseHTTPRequestHandler Python でタイムアウトを実装する方法
#!/usr/bin/env python
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import os
class handlr(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type','text-html')
self.end_headers()
self.wfile.write(os.popen('sleep 20 & echo "this took 20 seconds"').read())
def run():
server_address = ('127.0.0.1', 8080)
httpd = HTTPServer(server_address, handlr)
httpd.serve_forever()
if __name__ == '__main__':
run()
テストとして、実行に 20 秒かかるシェル コマンドを実行しているので、その前にサーバーを停止する必要があります。