diff options
Diffstat (limited to 'bitbake/lib/hashserv')
-rw-r--r-- | bitbake/lib/hashserv/__init__.py | 14 | ||||
-rw-r--r-- | bitbake/lib/hashserv/tests.py | 8 |
2 files changed, 16 insertions, 6 deletions
diff --git a/bitbake/lib/hashserv/__init__.py b/bitbake/lib/hashserv/__init__.py index 86aa7e9de6..1d5e08ee5a 100644 --- a/bitbake/lib/hashserv/__init__.py +++ b/bitbake/lib/hashserv/__init__.py | |||
@@ -13,6 +13,7 @@ import logging | |||
13 | import socketserver | 13 | import socketserver |
14 | import queue | 14 | import queue |
15 | import threading | 15 | import threading |
16 | import signal | ||
16 | from datetime import datetime | 17 | from datetime import datetime |
17 | 18 | ||
18 | logger = logging.getLogger('hashserv') | 19 | logger = logging.getLogger('hashserv') |
@@ -147,8 +148,14 @@ class ThreadedHTTPServer(HTTPServer): | |||
147 | self.handlerthread.daemon = False | 148 | self.handlerthread.daemon = False |
148 | 149 | ||
149 | self.handlerthread.start() | 150 | self.handlerthread.start() |
151 | |||
152 | signal.signal(signal.SIGTERM, self.sigterm_exception) | ||
150 | super().serve_forever() | 153 | super().serve_forever() |
151 | 154 | ||
155 | def sigterm_exception(self, signum, stackframe): | ||
156 | self.server_close() | ||
157 | os._exit(0) | ||
158 | |||
152 | def process_request_thread(self): | 159 | def process_request_thread(self): |
153 | while not self.quit: | 160 | while not self.quit: |
154 | try: | 161 | try: |
@@ -163,6 +170,7 @@ class ThreadedHTTPServer(HTTPServer): | |||
163 | self.handle_error(request, client_address) | 170 | self.handle_error(request, client_address) |
164 | finally: | 171 | finally: |
165 | self.shutdown_request(request) | 172 | self.shutdown_request(request) |
173 | os._exit(0) | ||
166 | 174 | ||
167 | def process_request(self, request, client_address): | 175 | def process_request(self, request, client_address): |
168 | self.requestqueue.put((request, client_address)) | 176 | self.requestqueue.put((request, client_address)) |
@@ -208,6 +216,8 @@ def create_server(addr, dbname, prefix=''): | |||
208 | cursor.execute('CREATE INDEX IF NOT EXISTS taskhash_lookup ON tasks_v2 (method, taskhash)') | 216 | cursor.execute('CREATE INDEX IF NOT EXISTS taskhash_lookup ON tasks_v2 (method, taskhash)') |
209 | cursor.execute('CREATE INDEX IF NOT EXISTS outhash_lookup ON tasks_v2 (method, outhash)') | 217 | cursor.execute('CREATE INDEX IF NOT EXISTS outhash_lookup ON tasks_v2 (method, outhash)') |
210 | 218 | ||
211 | logger.info('Starting server on %s', addr) | 219 | ret = ThreadedHTTPServer(addr, Handler) |
220 | |||
221 | logger.info('Starting server on %s\n', ret.server_port) | ||
212 | 222 | ||
213 | return ThreadedHTTPServer(addr, Handler) | 223 | return ret |
diff --git a/bitbake/lib/hashserv/tests.py b/bitbake/lib/hashserv/tests.py index 15f4a52ee9..6845b53884 100644 --- a/bitbake/lib/hashserv/tests.py +++ b/bitbake/lib/hashserv/tests.py | |||
@@ -6,7 +6,7 @@ | |||
6 | # | 6 | # |
7 | 7 | ||
8 | import unittest | 8 | import unittest |
9 | import threading | 9 | import multiprocessing |
10 | import sqlite3 | 10 | import sqlite3 |
11 | import hashlib | 11 | import hashlib |
12 | import urllib.request | 12 | import urllib.request |
@@ -21,16 +21,16 @@ class TestHashEquivalenceServer(unittest.TestCase): | |||
21 | self.dbfile = tempfile.NamedTemporaryFile(prefix="bb-hashserv-db-") | 21 | self.dbfile = tempfile.NamedTemporaryFile(prefix="bb-hashserv-db-") |
22 | self.server = create_server(('localhost', 0), self.dbfile.name) | 22 | self.server = create_server(('localhost', 0), self.dbfile.name) |
23 | self.server_addr = 'http://localhost:%d' % self.server.socket.getsockname()[1] | 23 | self.server_addr = 'http://localhost:%d' % self.server.socket.getsockname()[1] |
24 | self.server_thread = threading.Thread(target=self.server.serve_forever) | 24 | self.server_thread = multiprocessing.Process(target=self.server.serve_forever) |
25 | self.server_thread.daemon = True | ||
25 | self.server_thread.start() | 26 | self.server_thread.start() |
26 | 27 | ||
27 | def tearDown(self): | 28 | def tearDown(self): |
28 | # Shutdown server | 29 | # Shutdown server |
29 | s = getattr(self, 'server', None) | 30 | s = getattr(self, 'server', None) |
30 | if s is not None: | 31 | if s is not None: |
31 | self.server.shutdown() | 32 | self.server_thread.terminate() |
32 | self.server_thread.join() | 33 | self.server_thread.join() |
33 | self.server.server_close() | ||
34 | 34 | ||
35 | def send_get(self, path): | 35 | def send_get(self, path): |
36 | url = '%s/%s' % (self.server_addr, path) | 36 | url = '%s/%s' % (self.server_addr, path) |