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

Ability to retrieve submission information given a CallFuture object #485

Open
peterzahemszky opened this issue Aug 23, 2021 · 1 comment
Labels
type: enhancement New feature or request

Comments

@peterzahemszky
Copy link

Given a CallFuture object, it would be useful to be able to retrieve submission information (e.g. the args and kwargs that were submitted for the given CallFuture). These could be used for reporting results and errors to the user, and avoid writing boilerplate code for storing these states elsewhere.

Workaround no. 1: in addition to storing each CallFuture, we store a mapping from CallFuture to custom SubmissionInfo objects. The latter contains details about the task submission.
Workaround no. 2: we create a new attribute on each CallFuture instance using HasTraits.add_trait(). That attribute contains the submission info, which can be accessed when the task is finished. (The attribute cannot be set as usual. CallFuture inherits from the HasStrictTraits class, which prevents exactly that.)
Half-workaround (assuming exceptions are not used): modify the submitted function to also return its input parameters. This doesn’t work if the input parameters are needed for reporting errors too.

@peterzahemszky peterzahemszky added the design proposal Proposal for a change or new feature, for discussion label Aug 23, 2021
@mdickinson
Copy link
Member

we store a mapping from CallFuture to custom SubmissionInfo objects. The latter contains details about the task submission

There's already internally a BackgroundCall class that represents the task that was submitted. We could consider making that class (and the analogous classes for the other task types) available in traits_futures.api. A BackgroundCall instance can be submitted directly to a TraitsExecutor via the submit method. There's also a CallTask class which may be closer to what you need:

class CallTask(BaseTask):
"""
Wrapper around the actual callable to be run. This wrapper provides the
task that will be submitted to the concurrent.futures executor
"""
def __init__(self, callable, args, kwargs):
self.callable = callable
self.args = args
self.kwargs = kwargs
def run(self):
return self.callable(*self.args, **self.kwargs)
. Again, it's not currently part of traits_futures.api, but we could change that.

Workaround no. 2: we create a new attribute on each CallFuture instance using HasTraits.add_trait().

I wouldn't recommend this - a CallFuture instance is managed by the executor machinery, and is not intended to support being modified by the user. A better approach would be to create a compound object Submission (or whatever name is appropriate for your application) that contains references to both the call task and the CallFuture.

I'll think about possible solutions here. Having a reference from the future to the task doesn't feel right to me (and I'll note that concurrent.futures doesn't do this, either), but having a compound object available with references to both the future and the task may make sense.

@mdickinson mdickinson added type: enhancement New feature or request and removed design proposal Proposal for a change or new feature, for discussion labels Sep 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants