From: Michael Tremer Date: Fri, 26 May 2023 17:15:04 +0000 (+0000) Subject: daemon: Wrap Pakfire entirely into a thread X-Git-Tag: 0.9.29~150 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f4497d73788975f3865432063637ac3168b15980;p=pakfire.git daemon: Wrap Pakfire entirely into a thread This is an attempt to fix a couple of concurrency issues which cause that Pakfire does not cleanup any files on disk. Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/daemon.py b/src/pakfire/daemon.py index c3df4124e..9467b7d78 100644 --- a/src/pakfire/daemon.py +++ b/src/pakfire/daemon.py @@ -276,7 +276,7 @@ class Worker(multiprocessing.Process): # Run the build try: - build = self._build(pkg, arch=arch, target=target, + build = self.build(pkg, arch=arch, target=target, logger=logger._log, build_id=self.job_id, # Always disable using snapshots @@ -314,13 +314,18 @@ class Worker(multiprocessing.Process): packages=packages, ) - def _build(self, pkg, arch=None, logger=None, **kwargs): + def build(self, *args, **kwargs): """ Sets up a new Pakfire instance and runs it in a new thread. This method returns an async.Task() object which can be used to track if this job is still running. """ + thread = asyncio.to_thread(self._build, *args, **kwargs) + + return asyncio.create_task(thread) + + def _build(self, pkg, arch=None, logger=None, **kwargs): # Setup Pakfire instance try: p = _pakfire.Pakfire(arch=arch, conf=self.pakfire_conf, logger=logger) @@ -328,11 +333,8 @@ class Worker(multiprocessing.Process): # Delete the configuration file os.unlink(self.pakfire_conf) - # Run the build in a new thread - thread = asyncio.to_thread(p.build, pkg, **kwargs) - - # Return a task - return asyncio.create_task(thread) + # Run the build + return p.build(pkg, **kwargs) def shutdown(self): self.log.debug("Shutting down worker %s" % self.pid)