def start(self): Thread.start(self) # Automatically calls shutdown() when the returned token goes out of scope return ScopeGuard(self.shutdown)