title: Flask with Celery - workers exit with exitcode1
body: <p>I have a flask app with celery. <br> 
  When I am running the worker as follows:</p>
  
  <pre><code>celery -A app.celery worker
  </code></pre>
  
  <p>I get the following output</p>
  
  <pre><code> -------------- celery@local-pc v3.1.22 (Cipater)
  ---- **** -----
  --- * ***  * -- Windows-7-6.1.7601-SP1
  -- * - **** ---
  - ** ---------- [config]
  - ** ---------- .&gt; app:         app:0x483e668
  - ** ---------- .&gt; transport:   mongodb://localhost:27017/app
  - ** ---------- .&gt; results:     mongodb://localhost:27017/app
  - *** --- * --- .&gt; concurrency: 8 (prefork)
  -- ******* ----
  --- ***** ----- [queues]
   -------------- .&gt; celery           exchange=celery(direct) key=celery
  
  
  [2016-03-08 15:52:05,587: WARNING/MainProcess] celery@local-pc ready.
  [2016-03-08 15:52:08,855: ERROR/MainProcess] Process 'Worker-8' pid:9720 exited with 'exitcode 1'
  [2016-03-08 15:52:08,855: ERROR/MainProcess] Process 'Worker-7' pid:11940 exited with 'exitcode 1'
  [2016-03-08 15:52:08,856: ERROR/MainProcess] Process 'Worker-6' pid:13120 exited with 'exitcode 1'
  ...
  </code></pre>
  
  <p>It goes endlessly and the CPU raises to 100%.</p>
  
  <p>the relevant configuration is:</p>
  
  <pre><code>CELERY_BROKER_URL = 'mongodb://localhost:27017/app'
  CELERY_RESULT_BACKEND = 'mongodb://localhost:27017/'
  CELERY_MONGODB_BACKEND_SETTINGS = {
      'database': 'app',
      'taskmeta_collection': 'my_taskmeta_collection',
  }
  CELERY_IMPORTS = ('app.tasks', )
  CELERYD_FORCE_EXEC = True
  CELERY_ACCEPT_CONTENT = ['json']
  CELERY_TASK_SERIALIZER = 'json'
  CELERY_RESULT_SERIALIZER = 'json'
  </code></pre>
  
  <p>my project structure is:</p>
  
  <pre><code>proj/
      config.py
      app/
          __init__.py
          tasks.py
          views.py
  </code></pre>
  
  <p>this is how I configured my celery in ___init___.py":</p>
  
  <pre><code>app = Flask(__name__)
  app.config.from_object('config')
  db = SQLAlchemy(app)
  
  
  def make_celery(app):
      celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'])
      celery.conf.update(app.config)
      TaskBase = celery.Task
  
      class ContextTask(TaskBase):
          abstract = True
  
          def __call__(self, *args, **kwargs):
              with app.app_context():
                  return TaskBase.__call__(self, *args, **kwargs)
      celery.Task = ContextTask
      return celery
  
  celery = make_celery(app)
  </code></pre>
  
  <p>this is what I have in <code>tasks.py</code></p>
  
  <pre><code>from app import celery
  
  
  @celery.task()
  def add_together(a, b):
      return a + b
  </code></pre>
  
  <p><strong>update</strong> </p>
  
  <p>When I remove the following line from the config file the worker does not exit</p>
  
  <pre><code>CELERY_IMPORTS = ('app.tasks', )
  </code></pre>
  
  <p>but I get the following error</p>
  
  <pre><code>Traceback (most recent call last):
    File "d:\python34\lib\site-packages\celery\worker\consumer.py", line 456, in on_task_received
      strategies[name](message, body,
  KeyError: 'app.tasks.add_together'
  </code></pre>