Chognificent
Chognificent

Reputation: 413

Celery: Getting unexpected run_command() takes 1 positional argument but 318 were given error

I am attempting to run an async task and am getting an unexpected error: run_command() takes 1 positional argument but 318 were given. I have a list of commands that I want to run from a celery task.

run_command.chunks(iter(commands), 10).group().apply_async()

@task
def run_command(commands):
    for command in commands:
        print("RUNNING, ", command)
        print("Pid: ", os.getpid())
        os.system(command)

As shown above, I am attempting to break down my command into batches that will be executed in parallel.

Thanks for the help

Upvotes: 0

Views: 872

Answers (1)

Greenev
Greenev

Reputation: 909

Celery treats its positional arguments as *args, so every command in your commands iterable should looks like ('commandtext',)

commands = ['hello', 'world', '!']

@task
def run_command(command):
    '''run command'''

run_command.chunks(zip(commands), 2).group().apply_async()

Upvotes: 1

Related Questions