简体   繁体   English

当由pythonw.exe 3.1运行时,BaseHTTPRequestHandler挂起

[英]BaseHTTPRequestHandler hangs when being run by pythonw.exe 3.1

The following code works fine with python.exe but fails with pythonw.exe. 以下代码在python.exe上正常工作,但在pythonw.exe上失败。 I'm using Python 3.1 on Windows 7. 我在Windows 7上使用Python 3.1。

from http.server import BaseHTTPRequestHandler, HTTPServer

class FooHandler(BaseHTTPRequestHandler):
    def do_POST(self):
        length = int(self.headers['Content-Length'])
        data = self.rfile.read(length)
        print(data)
        self.send_response(200)
        self.send_header('Content-Length', '0')
        self.end_headers()

httpd = HTTPServer(('localhost', 8000), FooHandler)
httpd.serve_forever()

Something wrong when I start sending responses. 开始发送响应时出了点问题。 Nothing got written back. 什么都没写回来。 And if I try another http connection it won't connect. 如果我尝试其他http连接,它将无法连接。 I also tried using self.wfile but no luck either. 我也尝试使用self.wfile但也没有运气。

You are printing to stdout. 您正在打印到标准输出。 pythonw.exe doens't have a stdout, as it's not connected to a terminal. pythonw.exe没有标准输出,因为它没有连接到终端。 My guess is that this has something to do with it. 我的猜测是,这与它有关。

Try to redirect stdout to a file, or quicker, remove the print() . 尝试将标准输出重定向到文件,或者更快地删除print()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM