faulthandler turns a signal into a traceback from a hung process
A worker that stops making progress gives you nothing: no log line, no traceback, and attaching a debugger to a production container is rarely an option. One line at startup turns a signal into a stack dump of every thread.
import faulthandler, signal
faulthandler.register(signal.SIGUSR1, all_threads=True)Then kill -USR1 <pid> writes each thread's traceback to stderr, where your log shipper already collects it, and the process carries on. Send it twice: the same line both times is a block, a moving one is a slow loop.
pythondebuggingconcurrency