小编Ele*_*nae的帖子

多个请求后,Python SimpleHTTPServer挂起

我正在编写一个包含以下内容的简单集成测试:

  1. 启动一个简单的HTTP服务器来提供要测试的页面
  2. 启动加载该页面的各种不同的浏览器,以确认一切正常。

I know #2 works and I have no problem with this.

但是,#1仅适用于前几个浏览器,然后挂起,导致随后的浏览器测试失败。我真的不明白为什么。

在我的代码中,这是我正在做的事情:

class Test:  
    def setup_class(cls):  
        ready_signal = threading.Event()  
        cls.port = 9000  
        cls.docroot = /tmp  
        cls.http_wrapper = SimpleHTTPWrap(port=cls.port, docroot=cls.docroot, ready_signal)  
        background_thread = threading.Thread(target=http_wrapper.start)  
        background_thread.daemon = True  
        background_thread.start()  
        ready_signal.wait(10) # Wait for thread to be ready (or proceed after timeout)  
    def test(self):  
        ip = get_my_ip_address()  
        self.browser = webdriver.Remote(_some_parameters_go_here)  
        self.browser.get('http://' + ip + ":" + cls.port + cls.docroot + '/test.html')  
        # This hangs after similar tests have already …
Run Code Online (Sandbox Code Playgroud)

python simplehttpserver tcpserver socketserver

5
推荐指数
1
解决办法
1086
查看次数