aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Barker <pbarker@konsulko.com>2021-04-29 15:11:10 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-05-06 11:07:12 +0100
commitb3da56240c0f92efab1c0b293738c35c0f1ee6ab (patch)
tree323a01042722eaeac70e4e06c5cbd4a1f69cebcb
parentc5c4e49574ab2a65e06298a0a77bb98b041cf56b (diff)
downloadbitbake-contrib-b3da56240c0f92efab1c0b293738c35c0f1ee6ab.tar.gz
prserv: Use multiprocessing to auto start prserver
We can use the modern multiprocessing support in Python instead of manually using fork to start the prserver process. To do this we need to set up the signal handlers for the prserver process in the work_forever function (which is now used as the main function for this process). The old code to start the prserver process using fork is not removed in this commit as it is tightly intertwined with the daemonization code which will be refactored in a following commit. Signed-off-by: Paul Barker <pbarker@konsulko.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--lib/prserv/serv.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
index 4375d3e59..5d6520da8 100644
--- a/lib/prserv/serv.py
+++ b/lib/prserv/serv.py
@@ -15,6 +15,7 @@ import prserv
import prserv.db
import errno
import select
+import multiprocessing
logger = logging.getLogger("BitBake.PRserv")
@@ -149,6 +150,9 @@ class PRServer(SimpleXMLRPCServer):
# if there is data there.
self.timeout = 0.01
+ signal.signal(signal.SIGINT, self.sigint_handler)
+ signal.signal(signal.SIGTERM, self.sigterm_handler)
+
bb.utils.set_process_name("PRServ")
# DB connection must be created after all forks
@@ -228,8 +232,6 @@ class PRServer(SimpleXMLRPCServer):
os._exit(0)
def cleanup_handles(self):
- signal.signal(signal.SIGINT, self.sigint_handler)
- signal.signal(signal.SIGTERM, self.sigterm_handler)
os.chdir("/")
sys.stdout.flush()
@@ -283,8 +285,10 @@ class PRServSingleton(object):
self.port = None
def start(self):
- self.prserv = PRServer(self.dbfile, self.logfile, self.interface, daemon=False)
- self.prserv.start()
+ self.prserv = PRServer(self.dbfile, self.logfile, self.interface)
+ self.process = multiprocessing.Process(target=self.prserv.work_forever)
+ self.process.start()
+
self.host, self.port = self.prserv.getinfo()
def getinfo(self):