-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add new "steps" background task type #484
base: main
Are you sure you want to change the base?
Conversation
…feature/steps-future-only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly LGTM with one minor question.
#: Named arguments to be passed to the callable, excluding the "reporter" | ||
#: named argument. The "reporter" argument will be supplied through the | ||
#: execution machinery. | ||
kwargs = Dict(Str()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q : does this mean that the keys of the dictionary are strings and implicitly the value trait type isn't defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Possibly I should make that explicit by adding Any()
as a the value type.
Summary
This PR adds a new background task type, available through the
submit_steps
convenience function, returning aStepsFuture
. Like the existingsubmit_progress
, it can be used to run a cancellable progress-reporting background task. Unlikesubmit_progress
, it offers a richer interface for progress reporting to the background task.The plan is to add documentation, executable examples, and in particular example progress dialogs in a separate PR.
Usage example
The task type allows submission of a function like the following:
This task would be submitted using a call resembling:
The returned value
steps_future
is an instance ofStepsFuture
, and hasmessage
,total
andcomplete
traits that are updated with information about the currently-executing step, the total number of files to upload, and the number of uploads completed, respectively. These values could then be observed by a suitable progress dialog (an example such dialog can be found in #367).Details
The PR adds three items to
traits_futures.api
:submit_steps
, allowing submission of the progress-reporting taskStepsFuture
, for the return value ofsubmit_steps
. This inherits fromBaseFuture
and has the same future state as other task types, but also has public traitsmessage
,total
andcomplete
representing the progress stateIStepsReporter
that describes the extrareporter
argument that's supplied to the background task. This is potentially useful for projects that want to supply their own fakeIStepsReporter
instance while testing the functionality of the background task outside the Traits Futures frameworkImplementation notes
The state of the progress at any given time is represented by a
StepsState
instance: this is anamedtuple
subclass that holds three integers and a string:total
)complete
)pending
)message
)Both the
StepsFuture
and theStepsReporter
hold copies of the current state; every time the reporter'sstep
orstop
method is called, the local copy of the state is updated and then a message sent to the future with the updated state. When the future receives that message, it updates its own copy of the state. The three public traits (total
,complete
andmessage) on the
StepsFuture` are properties based on the private internal state. This avoids potential issues with listeners to those traits seeing different values depending on the order of updates.Further context
This PR is extracted from #367. See #367 for executable examples that make use of
submit_steps
and theStepsFuture
.Additional features planned
Some additional things that I think would be useful, but aren't planned to be included in this PR:
StepsFuture
modelStepsReporter.check
method that just checks for cancellation, and doesn't report any progress updatesNullStepsReporter
that implements theIStepsReporter
interface, but does nothing, for use in testingsubmit_progress
where the progress payload is used to transmit partial results