What's the difference between Celery task and subtask?
<p>If I understood the tutorial correctly, Celery <em>subtask</em> supports almost the same API as <em>task</em>, but has the additional advantage that it can be passed around to other functions or processes.</p>

<p>Clearly, if that was the case, Celery would have simply replaced <em>tasks</em> with <em>subtasks</em> instead of keeping both (e.g., the <code>@app.task</code> decorator would have converted a function to a <em>subtask</em> instead of to a <em>task</em>, etc.). So I must be misunderstanding something.</p>

<p>What can a <em>task</em> do that a <em>subtask</em> can't?</p>

<p>Celery API changed quite a bit; my question is specific to version 3.1 (currently, the latest).</p>

<p>Edit:</p>

<p>I know the docs say <em>subtasks</em> are intended to be called from other <em>tasks</em>. My question is what prevents Celery from getting rid of tasks completely and using subtasks everywhere? They seem to be strictly more flexible/powerful than tasks:</p>

<pre><code># tasks.py
from celery import Celery
app = Celery(backend='rpc://')

@app.task
def add(x, y):
    # just print out a log line for testing purposes
    print(x, y)

# client.py
from tasks import add
add_subtask = add.subtask()
# in this context, it seems the following two lines do the same thing
add.delay(2, 2)
add_subtask.delay(2, 2)
# when we need to pass argument to other tasks, we must use add_subtask
# so it seems add_subtask is strictly better than add
</code></pre>

<p>You will take the difference into account when you start using <a href="http://docs.celeryproject.org/en/latest/userguide/canvas.html" rel="nofollow">complex workflows</a> with celery.</p>

<blockquote>
  <p>A signature() wraps the arguments, keyword arguments, and execution
  options of a single task invocation in a way such that it can be
  passed to functions or even serialized and sent across the wire.</p>
  
  <p>Signatures are often nicknamed âsubtasksâ because they describe a task
  to be called within a task.</p>
</blockquote>

<p>Also:</p>

<blockquote>
  <p>subtaskâs are objects used to pass around the signature of a task
  invocation, (for example to send it over the network)</p>
</blockquote>

<p><code>Task</code> is just a function definition wrapped with decorator, but <code>subtask</code> is a task with parameters passed, but not yet started. You may transfer the subtask serialized over network or, more used, call it within a group/chain/chord.</p>

python celery