mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-09-14 16:18:05 -04:00
Proper fix for slow server bind
This commit is contained in:
parent
630fcbb38c
commit
60e6772254
@ -106,7 +106,7 @@ class TestFetchBackend(unittest.TestCase):
|
|||||||
br = browser_class(user_agent='test-ua', headers=(('th', '1'),), start_worker=True)
|
br = browser_class(user_agent='test-ua', headers=(('th', '1'),), start_worker=True)
|
||||||
|
|
||||||
def u(path=''):
|
def u(path=''):
|
||||||
return f'http://localhost:{self.port}{path}'
|
return f'http://{self.host}:{self.port}{path}'
|
||||||
|
|
||||||
def get(path='', headers=None, timeout=None, data=None):
|
def get(path='', headers=None, timeout=None, data=None):
|
||||||
url = u(path)
|
url = u(path)
|
||||||
@ -178,19 +178,23 @@ class TestFetchBackend(unittest.TestCase):
|
|||||||
|
|
||||||
def run_server(self):
|
def run_server(self):
|
||||||
from http.server import HTTPServer
|
from http.server import HTTPServer
|
||||||
|
from socketserver import TCPServer
|
||||||
|
|
||||||
def create_handler(*a):
|
def create_handler(*a):
|
||||||
ans = Handler(self, *a)
|
ans = Handler(self, *a)
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
httpd = HTTPServer(('localhost', 0), create_handler, bind_and_activate=False)
|
class Server(HTTPServer):
|
||||||
httpd.allow_reuse_address = True
|
|
||||||
httpd.allow_reuse_port = True
|
def server_bind(self):
|
||||||
with httpd:
|
# Avoid calling socket.getfqdn() which is slow on some systems
|
||||||
|
TCPServer.server_bind(self)
|
||||||
|
self.server_name, self.server_port = self.server_address[:2]
|
||||||
|
|
||||||
|
with Server(('localhost', 0), create_handler) as httpd:
|
||||||
self.server = httpd
|
self.server = httpd
|
||||||
httpd.server_bind()
|
|
||||||
self.port = httpd.server_port
|
self.port = httpd.server_port
|
||||||
httpd.server_activate()
|
self.host = httpd.server_name
|
||||||
self.server_started.set()
|
self.server_started.set()
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user