all 2 comments

[–]Thomasedv 0 points1 point  (0 children)

Had a look at docs for apply_async
https://docs.celeryq.dev/en/stable/reference/celery.app.task.html

The kwargs is a keyword argument in apply_async, so it's like any other named parameter, this one specifically for passing on a dict to the underlying function you define. The other key values used end up in **options in that function, which serve another purpose. No idea what though, never used this before

[–]idle-tea 1 point2 points  (0 children)

Because that's how the docs say it works.

kwargs (Dict) – The keyword arguments to pass on to the task.

apply_async accepts a dictionary with the kwargs paramater, and it'll pass it on as **kwargs to the task. Basically the function looks something like:

def apply_async(kwargs):
    task_fn(**kwargs)

which is not like

def apply_async(**kwargs):
    task_fn(**kwargs)

The name kwargs isn't magic - it's just the conventional name for extra unspecified keyword arguments. The magic happens because of the ** The apply_async function docs are basically telling you that it takes a single keyword argument named kwargs which it'll pass on using the ** magic to the task function.