From cc6ce13d150f0763c0eb716d4d9685363d1eac15 Mon Sep 17 00:00:00 2001 From: Jonathan Keane Date: Mon, 29 Jan 2024 19:46:46 -0600 Subject: [PATCH] a slightly nicer process monitor --- fflipper/fflipper.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fflipper/fflipper.py b/fflipper/fflipper.py index 7307b8c..df75a49 100755 --- a/fflipper/fflipper.py +++ b/fflipper/fflipper.py @@ -399,8 +399,10 @@ def clipPrep(self): def doClipping(self): # do the actual clipping # establish the number of cores available - numCores = multiprocessing.cpu_count() - freeProcs = numCores + # we divide in half the number of cores because ffmpeg itself is multi-core aware + numCores = multiprocessing.cpu_count() / 4 + # But we don't want this to be less than one + numCores = max(numCores, 1) print("Starting process monitoring.") nComplete = 0 nClips = len(self.annosToClip) @@ -409,14 +411,15 @@ def doClipping(self): while not allComplete: for singleAnno in self.annosToClip: if singleAnno["process"] is None: - if freeProcs > 0: + # count all the active processes (those that have a process and have no return code) + active_processes = sum([singAnn["process"] is not None and singAnn["process"].returncode is None for singAnn in self.annosToClip]) + if active_processes < numCores: # We have free processors, start starting jobs singleAnno["process"] = singleAnno["clipper"].clip() singleAnno["progress"].children["!progressbar"].config( mode="determinate" ) self.root.update() - freeProcs -= 1 else: # We continue if there are no freeProcs cause there will be no process to poll continue @@ -431,10 +434,8 @@ def doClipping(self): self.root.update() singleAnno["done"] = True - freeProcs += 1 else: singleAnno["done"] = True - freeProcs += 1 error_out = singleAnno["process"].stdout.read() error_button = Button(