summaryrefslogtreecommitdiffstats
path: root/lib/hashserv
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2019-07-31 10:49:39 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-08-06 11:21:07 +0100
commitbe23d887c8e244f1ef961298fbc9214d0fd0968a (patch)
treeadebaa0fff20d2ad052bff0c681a863046b38d3b /lib/hashserv
parenta03d60671a53d9ff70e07cc42fe35f6f8776dac2 (diff)
downloadbitbake-be23d887c8e244f1ef961298fbc9214d0fd0968a.tar.gz
hashserv: Switch from threads to multiprocessing
There were hard to debug lockups when trying to use threading to start hashserv as a thread. Switch to multiprocessing which doesn't show the same locking problems. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/hashserv')
-rw-r--r--lib/hashserv/__init__.py14
-rw-r--r--lib/hashserv/tests.py8
2 files changed, 16 insertions, 6 deletions
diff --git a/lib/hashserv/__init__.py b/lib/hashserv/__init__.py
index 86aa7e9de..1d5e08ee5 100644
--- a/lib/hashserv/__init__.py
+++ b/lib/hashserv/__init__.py
@@ -13,6 +13,7 @@ import logging
import socketserver
import queue
import threading
+import signal
from datetime import datetime
logger = logging.getLogger('hashserv')
@@ -147,8 +148,14 @@ class ThreadedHTTPServer(HTTPServer):
self.handlerthread.daemon = False
self.handlerthread.start()
+
+ signal.signal(signal.SIGTERM, self.sigterm_exception)
super().serve_forever()
+ def sigterm_exception(self, signum, stackframe):
+ self.server_close()
+ os._exit(0)
+
def process_request_thread(self):
while not self.quit:
try:
@@ -163,6 +170,7 @@ class ThreadedHTTPServer(HTTPServer):
self.handle_error(request, client_address)
finally:
self.shutdown_request(request)
+ os._exit(0)
def process_request(self, request, client_address):
self.requestqueue.put((request, client_address))
@@ -208,6 +216,8 @@ def create_server(addr, dbname, prefix=''):
cursor.execute('CREATE INDEX IF NOT EXISTS taskhash_lookup ON tasks_v2 (method, taskhash)')
cursor.execute('CREATE INDEX IF NOT EXISTS outhash_lookup ON tasks_v2 (method, outhash)')
- logger.info('Starting server on %s', addr)
+ ret = ThreadedHTTPServer(addr, Handler)
+
+ logger.info('Starting server on %s\n', ret.server_port)
- return ThreadedHTTPServer(addr, Handler)
+ return ret
diff --git a/lib/hashserv/tests.py b/lib/hashserv/tests.py
index 15f4a52ee..6845b5388 100644
--- a/lib/hashserv/tests.py
+++ b/lib/hashserv/tests.py
@@ -6,7 +6,7 @@
#
import unittest
-import threading
+import multiprocessing
import sqlite3
import hashlib
import urllib.request
@@ -21,16 +21,16 @@ class TestHashEquivalenceServer(unittest.TestCase):
self.dbfile = tempfile.NamedTemporaryFile(prefix="bb-hashserv-db-")
self.server = create_server(('localhost', 0), self.dbfile.name)
self.server_addr = 'http://localhost:%d' % self.server.socket.getsockname()[1]
- self.server_thread = threading.Thread(target=self.server.serve_forever)
+ self.server_thread = multiprocessing.Process(target=self.server.serve_forever)
+ self.server_thread.daemon = True
self.server_thread.start()
def tearDown(self):
# Shutdown server
s = getattr(self, 'server', None)
if s is not None:
- self.server.shutdown()
+ self.server_thread.terminate()
self.server_thread.join()
- self.server.server_close()
def send_get(self, path):
url = '%s/%s' % (self.server_addr, path)