title: What is the proper way to call a Celery task from within a task when I need to get the result and there is only one worker?
body: <p>I have a celery queue with a single worker (<code>--concurrency=1</code>). I have two tasks. One which calls an API (<code>call_api_task</code>). The other (<code>other_task</code>) calls a function which in turn calls the API task and waits for the result.</p>
  
  <pre><code>def update_data():
      data_to_api = '{"hello": "world"}'
      api_response = call_api_task.subtask(data_to_api).delay().get()
      return api_response
  
  @celery.task
  def call_api_task(data_to_api):
      # Call api with data_to_api
      return '{"success": "true"}'
  
  @celery.task
  def other_task():
      response = update_data()
      # Do something with response
  </code></pre>
  
  <p>The problem I'm running in to is that when <code>other_task</code> is called, it never completes. Based on the <a href="http://celery.readthedocs.io/en/latest/getting-started/next-steps.html#designing-workflows" rel="nofollow noreferrer">Celery docs</a> I thought that calling the task as a subtask should avoid this problem, but it seems I am missing something.</p>
  
  <h2>Possible resolutions I have considered</h2>
  
  <ol>
  <li><p>Add a parameter to <code>update_data</code> which allows it to know that it was called from <code>other_task</code>. Then call <code>call_api_task</code> without <code>subtask</code> &amp; <code>delay</code>.</p>
  
  <ul>
  <li>Problem: In the nontrivial example code there are several other functions between <code>other_task</code> and <code>update_data</code> which means I would have to pass that parameter around a lot. This would result in messy code.</li>
  </ul></li>
  <li><p>Add code in <code>update_data</code> to detect if it was called via a Celery task by checking <code>billiard.current_process()</code> properties.</p>
  
  <ul>
  <li>Problem: It seems like there should be a  more elegant way to accomplish this.</li>
  </ul></li>
  <li><p>Put <code>other_task</code> on a different Celery queue.</p>
  
  <ul>
  <li>This is what I am currently doing to solve the problem. I thought there should be a more elegant way to accomplish this.</li>
  </ul></li>
  </ol>
  
  <h2>Question</h2>
  
  <p>How can <code>update_data</code> call <code>call_api_task</code> directly (not as a task) when called from <code>other_task</code> without using possible resolution #1 or #2 above?</p>
  
  <h2>In response to possible duplicate of <a href="https://stackoverflow.com/questions/33280456">Calling async_result.get() from within a celery task</a></h2>
  
  <p>This question &amp; answers are specifically addressing "a celery task that calls another remote task (it's on a different celery app, in another server..)". This is not the case for my scenario. As pointed out above, I could put <code>other_task</code> on a separate Celery queue which would give the same end result as the scenario of this question but I thought there should be a more elegant way to accomplish this.</p>