]> git.ipfire.org Git - pakfire.git/commitdiff
daemon: Wrap Pakfire entirely into a thread
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 26 May 2023 17:15:04 +0000 (17:15 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 26 May 2023 17:15:04 +0000 (17:15 +0000)
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 <michael.tremer@ipfire.org>
src/pakfire/daemon.py

index c3df4124e1a7874b7ab1a4f02496508066e8cccf..9467b7d781fd7d84561a3f1ca48cd5d8da067c37 100644 (file)
@@ -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)