commit c71b2f32a3dd9439b1276313b1617ccd23c66c79
parent 0b2e33615131353189a517ba0de86b25dacecf7f
Author: St John Karp <contact@stjo.hn>
Date: Sun, 22 Aug 2021 14:45:38 -0400
Fix problem where `wait` returns too soon
`wait` doesn't seem to wait until all child processes have finished.
It may just be returning after all the `swipl` processes are done,
but there are visibly still Markdown, `sed`, and `smartypants` processes
still running. I've implemented a hack that just checks for any
`sed` and `smartypants` processes after wait returns. This works
more effectively and ensures the Markdown/HTML processing is done
before moving on to the next steps (e.g. generating the RSS feed).
This was the real cause of the bug a couple of commits back where
unsqueeze.sh would produce empty HTML files --- it was a race condition.
Diffstat:
2 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/squeeze.sh b/squeeze.sh
@@ -35,6 +35,12 @@ find "$SOURCE_PATH" -type f -name "*.md" |
# Wait until all jobs have completed.
wait
+# The `wait` command doesn't seem to wait for all the running jobs.
+# Maybe it's stopping after all `swipl` processes complete?
+# This hack just checks to see if any sed or smartypants processes are running.
+while [ $(ps -A | grep -c -e " sed$" -e " smartypants$") -gt 0 ]; do
+ sleep 1
+done
# Generate the RSS feed.
mkdir -p "$OUTPUT_PATH/feeds"
diff --git a/unsqueeze.sh b/unsqueeze.sh
@@ -42,3 +42,9 @@ find "$OUTPUT_PATH" -type f -name "*.html" |
# Wait until all jobs have completed.
wait
+# The `wait` command doesn't seem to wait for all the running jobs.
+# Maybe it's stopping after all `swipl` processes complete?
+# This hack just checks to see if any sed processes are running.
+while [ $(ps -A | grep -c " sed$") -gt 0 ]; do
+ sleep 1
+done