bitbake: 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.

(Bitbake rev: b3da56240c0f92efab1c0b293738c35c0f1ee6ab)

Signed-off-by: Paul Barker <pbarker@konsulko.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Paul Barker
2021-04-29 15:11:10 +01:00
committed by Richard Purdie
parent 581233a798
commit 802024fd2a

View File

@@ -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):