title: How to start a Celery worker from a script/module __main__?
body: <p>I've define a <code>Celery</code> app in a module, and now I want to start the worker from the same module in its <code>__main__</code>, i.e. by running the module with <code>python -m</code> instead of <code>celery</code> from the command line. I tried this:</p>
  
  <pre><code>app = Celery('project', include=['project.tasks'])
  
  # do all kind of project-specific configuration
  # that should occur whenever this module is imported
  
  if __name__ == '__main__':
      # log stuff about the configuration
      app.start(['worker', '-A', 'project.tasks'])
  </code></pre>
  
  <p>but now Celery thinks I'm running the worker without arguments:</p>
  
  <pre><code>Usage: worker &lt;command&gt; [options] 
  
  Show help screen and exit.
  
  Options:
    -A APP, --app=APP     app instance to use (e.g. module.attr_name)
  [snip]
  </code></pre>
  
  <p>The usage message is the one you get from <code>celery --help</code>, as if it didn't get a command. I've also tried</p>
  
  <pre><code>app.worker_main(['-A', 'project.tasks'])
  </code></pre>
  
  <p>but that complains about the <code>-A</code> not being recognized.</p>
  
  <p>So how do I do this? Or alternatively, how do I pass a callback to the worker to have it log information about its configuration?</p>