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

Expose execution details from Executor to user level (eg Context) #443

thedrow opened this issue May 22, 2017 · 5 comments

Expose execution details from Executor to user level (eg Context) #443

thedrow opened this issue May 22, 2017 · 5 comments


Copy link

thedrow commented May 22, 2017

[Maintainer edit: this ticket is now about all general "what is the overall execution system up to?" functionality - current task, that task's args, results of CLI parsing, etc]

I'd like to print a progress bar that shows how many tasks have completed and how many remain.
The API currently does not expose these statistics as far as I know.
Is there any way I'm not familiar with to count the number of pending and completed tasks?

Copy link

Nope, that's not implemented, but the statistics themselves would want to live in the Executor class most likely, and it would probably not be hard to just make it generally available to any code that has a handle on that object.

How to use the resulting data is a bit tougher since I assume you want either A) ability to access it within a task, via the context, or B) a general internal/core behavior where e.g. the Executor is itself displaying this progress bar as it goes.

I'm curious about your real-world use case! Most tasks I'm familiar with tend to have some output as they run (even if it's high level log-esque statements and not command stdout) so a progress bar doesn't work too well there, only if there is no other output.

(That said, I've experimented with a hybrid "one output line per task/subtask, and spinners/progress bars for commands that are known to take a long time" approach in some non-public tasks for my job, using libraries like humanfriendly and tdqm. Making those helper/util functions publicly available would be nice.)

@bitprophet bitprophet changed the title Execution progress Expose execution details from Executor to user level (eg Context) Jun 19, 2018
Copy link

Note to self, this may need a little bit of extension for Fabric as well, re: current host in a host list / current role / etc, though if those are couched in general enough terms (re: parameterization of a task) it may end up working 100% through the Invoke side of things.

Copy link
Contributor Author

thedrow commented Jun 21, 2018

I kinda missed this issue.
My usecase was to create a progress bar and place it somewhere on the screen using ncurses or something.

@bitprophet bitprophet added this to the 1.4 milestone Jun 28, 2018
Copy link

DylanYoung commented Dec 7, 2022

Here's a way to access the current Call object in case anyone needs a workaround (you can also access calls from the same stack frame, which would allow a progress indicator):

def get_current_task_call():
    # See
    # and
    frame = inspect.currentframe().f_back
    while frame:
        if frame.f_code.co_filename.endswith(""):
            if "call" in frame.f_locals:
                call = frame.f_locals["call"]
                del frame
                return call
        frame = frame.f_back
    del frame
    raise ValueError(
        "get_current_task_name must be called in an invoke context",

I'd recommend taking a look at Rich or Textual rather than ncurses: or

Copy link

cuu508 commented Jul 21, 2023

I'm also looking at ways to communicate progress to the user while tasks run. Instead of a progress bar, I was thinking of something much simpler: when each task starts, Invoke prints a line "Task such-and-such starts" in the console, and perhaps a similar line when a task finishes. I can of course add my own print statement at the start of every task, but this could also be something that Invoke does (as an option, with a CLI flag like --log-progress or something like that).

The --debug parameter sort of does this, in the output I see lines like:

invoke.executor.execute: Executing <Call 'foo' (called as: ' args: (), kwargs: {}>

But it also prints a lot more :-)

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

No branches or pull requests

4 participants