{"action":"created","issue":{"url":"https://api.github.com/repos/celery/celery/issues/2119","labels_url":"https://api.github.com/repos/celery/celery/issues/2119/labels{/name}","comments_url":"https://api.github.com/repos/celery/celery/issues/2119/comments","events_url":"https://api.github.com/repos/celery/celery/issues/2119/events","html_url":"https://github.com/celery/celery/issues/2119","id":37078666,"number":2119,"title":"Exceptions in tasks autodiscover are not handled when worker is detached","user":{"login":"DXist","id":828007,"avatar_url":"https://avatars.githubusercontent.com/u/828007?v=3","gravatar_id":"","url":"https://api.github.com/users/DXist","html_url":"https://github.com/DXist","followers_url":"https://api.github.com/users/DXist/followers","following_url":"https://api.github.com/users/DXist/following{/other_user}","gists_url":"https://api.github.com/users/DXist/gists{/gist_id}","starred_url":"https://api.github.com/users/DXist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DXist/subscriptions","organizations_url":"https://api.github.com/users/DXist/orgs","repos_url":"https://api.github.com/users/DXist/repos","events_url":"https://api.github.com/users/DXist/events{/privacy}","received_events_url":"https://api.github.com/users/DXist/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2014-07-03T12:53:35Z","updated_at":"2015-06-19T11:03:40Z","closed_at":"2015-06-19T11:03:40Z","body":"Celery worker fails silently and with 0 retcode when exception is occured in `app.autodiscover_tasks`.\r\n\r\nIn my case the problem was in circular import when import starts from `tasks.py` module. Here is part of the traceback:\r\n```\r\nTraceback (most recent call last):\r\n  File \"/home/srk/envs/madmin/bin/celery\", line 9, in <module>\r\n    load_entry_point('celery==3.2.0a2', 'console_scripts', 'celery')()\r\n  File \"/home/srk/workspace/celery/celery/__main__.py\", line 30, in main\r\n    main()\r\n  File \"/home/srk/workspace/celery/celery/bin/celery.py\", line 82, in main\r\n    cmd.execute_from_commandline(argv)\r\n  File \"/home/srk/workspace/celery/celery/bin/celery.py\", line 778, in execute_from_commandline\r\n    super(CeleryCommand, self).execute_from_commandline(argv)))\r\n  File \"/home/srk/workspace/celery/celery/bin/base.py\", line 306, in execute_from_commandline\r\n    return self.handle_argv(self.prog_name, argv[1:])\r\n  File \"/home/srk/workspace/celery/celery/bin/celery.py\", line 770, in handle_argv\r\n    return self.execute(command, argv)\r\n  File \"/home/srk/workspace/celery/celery/bin/celery.py\", line 702, in execute\r\n    ).run_from_argv(self.prog_name, argv[1:], command=argv[0])\r\n  File \"/home/srk/workspace/celery/celery/bin/worker.py\", line 179, in run_from_argv\r\n    return self(*args, **options)\r\n  File \"/home/srk/workspace/celery/celery/bin/base.py\", line 269, in __call__\r\n    ret = self.run(*args, **kwargs)\r\n  File \"/home/srk/workspace/celery/celery/bin/worker.py\", line 212, in run\r\n    state_db=self.node_format(state_db, hostname), **kwargs\r\n  File \"/home/srk/workspace/celery/celery/worker/__init__.py\", line 97, in __init__\r\n    self.app.loader.init_worker()\r\n  File \"/home/srk/workspace/celery/celery/loaders/base.py\", line 128, in init_worker\r\n    self.import_default_modules()\r\n  File \"/home/srk/workspace/celery/celery/loaders/base.py\", line 116, in import_default_modules\r\n    signals.import_modules.send(sender=self.app)\r\n  File \"/home/srk/workspace/celery/celery/utils/dispatch/signal.py\", line 166, in send\r\n    response = receiver(signal=self, sender=sender, **named)\r\n  File \"/home/srk/envs/madmin/lib/python2.7/site-packages/amqp/promise.py\", line 221, in __call__\r\n    return self.set_error_state()\r\n  File \"/home/srk/envs/madmin/lib/python2.7/site-packages/amqp/promise.py\", line 217, in __call__\r\n    **(dict(self.kwargs, **kwargs) if kwargs else self.kwargs)\r\n  File \"/home/srk/workspace/celery/celery/app/base.py\", line 350, in _autodiscover_tasks\r\n    self.loader.autodiscover_tasks(packages, related_name)\r\n  File \"/home/srk/workspace/celery/celery/loaders/base.py\", line 251, in autodiscover_tasks\r\n    related_name) if mod)\r\n  File \"/home/srk/workspace/celery/celery/loaders/base.py\", line 272, in autodiscover_tasks\r\n    return [find_related_module(pkg, related_name) for pkg in packages]\r\n  File \"/home/srk/workspace/celery/celery/loaders/base.py\", line 291, in find_related_module\r\n    return importlib.import_module('{0}.{1}'.format(package, related_name))\r\n  File \"/usr/lib64/python2.7/importlib/__init__.py\", line 37, in import_module\r\n    __import__(name)\r\n  ..... application related import cycle is omitted ...\r\n```\r\n\r\nIt's possible to emulate this behaviour using following callback for `app.autodiscover_tasks`:\r\n```\r\ndef autodiscoverer():\r\n    raise RuntimeError('foo')\r\napp.autodiscover_tasks(autodiscoverer)\r\n```"},"comment":{"url":"https://api.github.com/repos/celery/celery/issues/comments/113474122","html_url":"https://github.com/celery/celery/issues/2119#issuecomment-113474122","issue_url":"https://api.github.com/repos/celery/celery/issues/2119","id":113474122,"user":{"login":"DXist","id":828007,"avatar_url":"https://avatars.githubusercontent.com/u/828007?v=3","gravatar_id":"","url":"https://api.github.com/users/DXist","html_url":"https://github.com/DXist","followers_url":"https://api.github.com/users/DXist/followers","following_url":"https://api.github.com/users/DXist/following{/other_user}","gists_url":"https://api.github.com/users/DXist/gists{/gist_id}","starred_url":"https://api.github.com/users/DXist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DXist/subscriptions","organizations_url":"https://api.github.com/users/DXist/orgs","repos_url":"https://api.github.com/users/DXist/repos","events_url":"https://api.github.com/users/DXist/events{/privacy}","received_events_url":"https://api.github.com/users/DXist/received_events","type":"User","site_admin":false},"created_at":"2015-06-19T11:03:40Z","updated_at":"2015-06-19T11:03:40Z","body":"Yes, you are right. Thank you for reminding about this issue!"}}