The Insane __init__ Method That Almost Broke My Sanity

2025-04-19
The Insane __init__ Method That Almost Broke My Sanity

A Python service test intermittently failed due to a bizarre __init__ method. The FooBarWidget class, in its __init__, starts a new thread to execute its parent class FooWidget's __init__ and run methods. This design attempts to avoid blocking the main thread because zmq.Socket objects can't be moved between threads. However, closing a FooBarWidget instance too early might leave FooWidget's __init__ unfinished, resulting in a missing 'should_exit' attribute and an error. This humorous account details the debugging ordeal and explores the rationale behind this unconventional design.

Development