title: Check if in celery task
body: <p>How to check that a function in executed by <a href="http://flask.pocoo.org/docs/0.10/patterns/celery/#minimal-example" rel="nofollow">celery</a>?</p>
  
  <pre><code>def notification():
     # in_celery() returns True if called from celery_test(), 
     #                     False if called from not_celery_test()
     if in_celery():
        # Send mail directly without creation of additional celery subtask
        ...
     else:
        # Send mail with creation of celery task
        ...
  
  @celery.task()
  def celery_test():
      notification()
  
  def not_celery_test():
      notification()
  </code></pre>