0

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

3
  • It here passes the commands as positional parameters. Commented Sep 10, 2019 at 10:50
  • @WillemVanOnsem, any suggestions on how I could potentially prevent this, if it is the issue? Commented Sep 10, 2019 at 11:51
  • wrap the items in singleton tuples before passing it to iter(..). Commented Sep 10, 2019 at 11:52

1 Answer 1

1

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.