Requirements.txt as Discipline: Stdlib-Only Scripts Need No Install
说明与用途
将管道拆分为仅使用Python标准库的小脚本,消除了重复发布问题,并使整个工作流程能够在2 GB服务器上运行,无需安装任何依赖项。
问题
Running a batch twice caused a double‑post flag on a stock platform, despite no crashes or errors.
结果
The refactored pipeline produced 39 finished products (856 MB) on a single‑core, 2 GB server without installing any packages, and eliminated double‑post flags.
工作流
- Split the original pipeline into four scripts: make_metadata.py, upload_tracker.py, md2pdf.py, pack_product.py.
- Make make_metadata.py and upload_tracker.py depend only on the standard library.
- Use upload_tracker.py to record posted assets and prevent re‑runs from double‑posting.
- Run make_metadata.py with arguments like "python make_metadata.py ./my-assets --platform adobe --out metadata.csv --ext .jpg" to generate platform‑specific CSV headers.
- Use md2pdf.py and pack_product.py for rendering, installing only Pillow and reportlab as needed.
- Follow resource limits: single process, gc.collect() after each asset, measure peak RSS, run heavy renders in separate subprocesses, inspect previews at 60 dpi.
- Maintain a fixed folder layout for assets, output, packs, research, and scripts.
- Keep the research folder permanently for future product creation.
- Deploy the scripts on any machine with Python 3.9+ without creating a virtual environment or installing dependencies.
证据
The second time I ran my upload batch, I got the email I had been dreading. A channel had flagged my account for double-posting.
I split my pipeline into small standalone scripts, I made two of them depend on nothing but the Python standard library, and I wrote a tracker so a re‑run could never double-post again.
That split is the whole point. A CSV generator and a ledger are pure text and logic. They have no business pulling in an image library, and when they do not, you can run them anywhere Python exists.
On a 1 vCPU, 2 GB box with no GPU, the pipeline only works if you respect those limits: One process at a time. Never fan out image jobs in parallel on a single-core box.
- 记录日期: 2026-10-24T19:26:38.385Z