Monkey patching
summary
Uses Python monkey patching to replace standard threading.Thread and multiprocessing Process behavior, adding an exception field, wrapping original run, and sending SIGUSR1 from threads and SIGUSR2 from processes. Processes serialize exception args and traceback to strings and send them over a channel; parent waits on an event with a 1 second timeout to ensure delivery. Built signal handlers re-raise the original exception in the main process; it works and turns long 60s mystery failures into immediate, specific errors like a missing install script.
AI-written summary · about
chapters (8)
- 0:00Introduction
- 2:13What is monkey patching
- 3:38Monkey patching example
- 5:27Thread exceptions problem
- 9:41Thread class modification
- 17:39Process class modification
- 24:33Results and benefits
- 25:59Q&A
related talks
28mKnocking On A Process’s Door: Introspecting Live Python Processes
40mAdvanced asyncio: Solving Real-world Production Problems
31mHear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.
45mDon't Live Patch Your CPython Interpreter
25mFinding penguins with a snake Linux features for a Python user
01h 31mIt's the message, stupid: python & amqp
32mWriting Extension Modules To Be Interruptible
39mUnlocking the Parallel Universe: Subinterpreters and Free-Threading in...
