QFX LABMADE UP. MADE REAL. Send a brief

HOME / TRICKS[N° T04] · UPDATED 2026-11-19

Why your "wait for the render, then encode" loop never ends

pgrep -f searches full command lines, including the line of the shell running your loop. The loop waits for itself. A one-character fix.

ShellRender queue3 MIN READ

BY · PUBLISHED

A common way to chain overnight jobs on one machine: wait until the render process is gone, then run the finishing step. It looks harmless:

LOOKS FINE, WAITS FOREVER
while pgrep -f "render_shot.py" >/dev/null; do sleep 30; done
bash finish.sh

If this loop runs inside bash -c '…', or inside a script whose command line contains render_shot.py, then pgrep -f matches that shell too. The render finishes, the loop keeps finding "render_shot.py" in its own command line, and the finishing step never starts. On the QX-Core render this cost 40 minutes before anyone noticed.

Fix 1: the bracket trick

MATCHES THE PROCESS, NOT THE PATTERN
while pgrep -f "[r]ender_shot.py" >/dev/null; do sleep 30; done

The regex [r]ender_shot.py still matches the text render_shot.py, but the literal string [r]ender_shot.py in your own command line does not match it. Same trick works for pkill -f, where the self-match is worse: it kills your own shell.

Fix 2: match the real binary

BASH
pgrep -f "[h]ython-bin render_shot.py"

Fix 3: do not poll at all

BEST WHEN YOU START BOTH JOBS
hython render_shot.py && bash finish.sh
# or, if the render is already running in this shell:
wait "$RENDER_PID" && bash finish.sh
Rule of thumbPolling by name is for jobs you did not start. If you started the render, chain on its exit code instead.
++++
QFX-BRIEF · ASYNC INTAKEWRITTEN · NO CALLS

Want something like this built for your product?

Send a short brief by email: the product, where the video or game will run, and when you need it. I reply in writing within a day with an approach and a quote for that project.

[email protected] · REPLY WITHIN 1 WORKING DAY