Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: taskN() got an unexpected keyword argument 'num_workers' #927

Open
Jesus-Gonzalez-Alight opened this issue Jun 24, 2024 · 3 comments

Comments

@Jesus-Gonzalez-Alight
Copy link

Hello Community,

I have a script which runs a main Nornir task, let's call it task1 and several sub-tasks inside task1, let's call it task2, taskN.
taskN is the last task and it attempts to commit changes based on user inputs: Y / N.

I would like to run each task before taskN in a threaded way but taskN should run with num_workers as 1.
Based on the documentation, https://nornir.readthedocs.io/en/latest/plugins/execution_model.html this is possible.
When I enter the argument in the following way:
task.run(task=taskN, num_workers = 1)
I get the error described in the title:
TypeError: taskN() got an unexpected keyword argument 'num_workers'

Nornir version which is running is 3.4.1.

I would appreciate any suggestions on how to achieve this without modifying the core_options and running every task in a non-threaded way.

Thanks,
Jesús

@dbarrosop
Copy link
Contributor

You can't pass num_workers to a subtask's run, only to the main nornir object's run.

@ktbyers
Copy link
Collaborator

ktbyers commented Jun 25, 2024

The referenced document is very old...not sure where it is located, but it should be updated or removed.

@ktbyers
Copy link
Collaborator

ktbyers commented Jun 26, 2024

@Jesus-Gonzalez-Alight You probably need to think of a different pattern. Basically once you call Task1 you are going to be in a child thread and all of the sub-tasks (Task2...TaskN) would be inside of that child thread. So what you are asking is to somehow go from the child thread back to the main thread.

So that is what you should really be thinking about doing--end Task1 and pass back whatever data you need (from Task1) and then back in the main thread (outside of the initial Task1 call), execute this last TaskN. For executing this last TaskN, there are different ways you could do this (to make it be non-threaded). I would probably look at these environment variables:

https://nornir.readthedocs.io/en/latest/configuration/index.html#runner

NORNIR_RUNNER_PLUGIN and the NORNIR_RUNNER_OPTIONS

Note, in Nornir Version3 the num_workers=X argument does not work for nr.run() calls. You used to be able to do this in Nornir Version2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants