def managed(cls, hostname=None, caller=None): hostname = hostname or socket.gethostname() if caller: hostname = ".".join([qualname(caller), hostname]) else: hostname += str(cls.next_worker_id()) worker = cls(hostname) worker.ensure_started() stack = traceback.format_stack() @atexit.register def _ensure_shutdown_once(): if not worker._shutdown_called: say("-- Found worker not stopped at shutdown: %s\n%s" % (worker.hostname, "\n".join(stack))) worker.ensure_shutdown() return worker
def test_qualname(self): Class = type("Fox", (object, ), {"__module__": "quick.brown"}) self.assertEqual(utils.qualname(Class), "quick.brown.Fox") self.assertEqual(utils.qualname(Class()), "quick.brown.Fox")
def test_evalutes_qualnames(self): self.assertEqual(prepare(qualname(MyAnnotation))[0]().foo, 65) self.assertEqual(prepare([qualname(MyAnnotation)])[0]().foo, 65)