def producer(self, producer_instance): with producer_instance as producer: yield producer assert len(multiprocessing.active_children()) == 0