Skip to content

Commit

Permalink
a slightly nicer process monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkeane committed Jan 30, 2024
1 parent 9b13eb2 commit cc6ce13
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions fflipper/fflipper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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(
Expand Down

0 comments on commit cc6ce13

Please sign in to comment.