Python2 minutes to read

Why do my Python worker logs appear all at once?

Test whether stdout buffering explains late Python logs, make progress visible during a long batch, and distinguish delayed output from a stuck worker.

Why a running worker can look silent

Python can buffer standard output when a hosting console collects it through a pipe. Several print() calls may appear together when the buffer fills or the program exits. Add flush=True to a progress message you need immediately. If the new message never appears, investigate startup or the operation the worker is waiting on. Python’s print and flush behavior.

Compare the timestamp inside each message

On a test worker, replace the entry file with this short timing check. Watch Console while it runs. You should see the three checkpoint messages roughly two seconds apart. Their embedded UTC timestamps show when Python produced them, independently of when you saw them in the browser.

A finite timing check in main.py
from datetime import datetime, timezone
from time import sleep

for step in range(1, 4):
    print(step, datetime.now(timezone.utc).isoformat(), flush=True)
    sleep(2)

This test finishes after three iterations. To monitor a continuously running example, try the Python worker starter, which flushes one heartbeat per minute. Confirm that a second heartbeat appears before adding your own queue or API client.

Find the operation that is taking time

For a batch worker, add a flushed message before reading a batch and another after saving it. Include a batch ID and record count. If the first appears and the second never arrives, inspect the read, transformation and save separately. For a queue consumer, an empty queue is a legitimate waiting state. Submit one known test item and follow its ID through those messages.

Use counters and identifiers you can safely share. A complete request body, private token or customer message adds noise and can expose user data in Console. If Console shows an import traceback before either checkpoint, fix that startup error first. Diagnose a missing Python module.