This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Make concurrent.futures.Future state public
Type: enhancement Stage: needs patch
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: bquinlan, jjdominguezm, pitrou
Priority: normal Keywords: patch

Created on 2012-01-14 17:07 by jjdominguezm, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
concurrent.futures.Future.state_public.patch jjdominguezm, 2012-01-14 17:07 Patch to make concurrent.futures.Future state public and a history property review
Messages (11)
msg151259 - (view) Author: Juan Javier (jjdominguezm) Date: 2012-01-14 17:07
Hello,

This is a proposal to make the state of Future objects public.

The idea is to have access to the current state of the Future using a property instead of calling several methods (done, cancelled, etc.).

Also, a history property that returns a list of Event(state, timestamp) objects is written, the list stores the timestamp every time the state of a future changes.

There is a patch attached to the issue.

Regards.
msg151268 - (view) Author: Brian Quinlan (bquinlan) * (Python committer) Date: 2012-01-14 21:00
Thanks for the patch!

1. The fetching the state feature seems reasonable but I think that explaining the difference between CANCELLED and CANCELLED_AND_NOTIFIED is going to be hard. Maybe you could look at how Doc/library/concurrent.futures.rst would need to be updated to see if we can provide a reasonable description of the different states?

2. Having the future record the history of its state transitions seems potentially useful but there is no precedent for this in other Python objects where it would also be useful. Maybe you could make the executors take a Futures factory and then provide a subclass that does that? Not sure that I like that either but...
msg151299 - (view) Author: Juan Javier (jjdominguezm) Date: 2012-01-15 21:02
Hello,

You're right, explaining the difference between CANCELLED and CANCELLED_AND_NOTIFIED is gong to be hard and might be confusing. I also agree that there is no precedent for storing the history of something, and I don't like either the idea of having a futures factory (that was my first idea).

But, what about using callbacks? it is possible to add done callbacks, why can't we have a list of callbacks attached to each "public" state.

Something like:

Future.append_callback(self, state: "One of PENDING, RUNNING, CANCELLED, FINISHED", fn)
msg151303 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-01-15 23:04
> The idea is to have access to the current state of the Future using a property instead of calling several methods (done, cancelled, etc.).

I think one point of having methods is that querying is decoupled from implementation. The internal states could for example be finer-grained than what is exposed by the API.

> Also, a history property that returns a list of Event(state, timestamp) objects is written, the list stores the timestamp every time the state of a future changes.

Uh, what is the use case exactly?
msg154631 - (view) Author: Juan Javier (jjdominguezm) Date: 2012-02-29 14:06
The use case is to know the state of a future without having to do something like this

    @property
    def state(self):
        if self.future.running():
            return Process.States.Running
        elif self.future.cancelled():
            return Process.States.Cancelled
        elif self.future.done():
            return Process.States.Done
        return Process.States.Pending
msg155115 - (view) Author: Brian Quinlan (bquinlan) * (Python committer) Date: 2012-03-07 20:14
I guess the question is: why do you need to know the state in that form?
msg155213 - (view) Author: Juan Javier (jjdominguezm) Date: 2012-03-09 08:54
I'm writting an application where users can submit long running jobs and I want to disply a list of those jobs and the state of each one.

My idea is to use an executor and use the futures to display information about the jobs: not started, cancelled, running, etc.

Think of a table with these headers:

ID, Start date, Last state change date, State, Info
msg165782 - (view) Author: Brian Quinlan (bquinlan) * (Python committer) Date: 2012-07-18 15:01
My current thinking is that adding a "state" property probably isn't worth it given the fact that you can construct this yourself and the requirement for a "history" property is too specialized.

The callback idea seams reasonable and sufficient for your use case. I think that you'd probably want to *not* specify that state change that you want i.e. any state change triggers the function.

What do you think?

(BTW, I'm on leave right now so it might take a while to respond)
msg165799 - (view) Author: Juan Javier (jjdominguezm) Date: 2012-07-18 20:52
I totally agree, I'm going to take a look at the code and I'll write back with some comments. That will be next week, work is currently very demanding.
msg201270 - (view) Author: Brian Quinlan (bquinlan) * (Python committer) Date: 2013-10-25 18:00
Any progress on this or can I close the bug?
msg201397 - (view) Author: Juan Javier (jjdominguezm) Date: 2013-10-26 21:18
Hi Brian,

No, no progress on this. I think this is not an interesting feature after all. You can close this.

Juan Javier
History
Date User Action Args
2022-04-11 14:57:25adminsetgithub: 57994
2013-10-26 21:19:57jjdominguezmsetstatus: open -> closed
2013-10-26 21:18:25jjdominguezmsetmessages: + msg201397
2013-10-25 18:00:47bquinlansetmessages: + msg201270
2012-10-21 09:15:08bquinlansetstage: needs patch
2012-07-18 20:52:58jjdominguezmsetstatus: languishing -> open

messages: + msg165799
versions: + Python 3.4, - Python 3.3
2012-07-18 15:01:21bquinlansetmessages: + msg165782
2012-07-18 10:26:06jjdominguezmsetstatus: open -> languishing
2012-03-09 08:54:03jjdominguezmsetmessages: + msg155213
2012-03-07 20:14:06bquinlansetmessages: + msg155115
2012-02-29 14:06:04jjdominguezmsetmessages: + msg154631
2012-01-15 23:04:50pitrousetnosy: + pitrou
messages: + msg151303
2012-01-15 21:02:23jjdominguezmsetmessages: + msg151299
2012-01-14 21:00:15bquinlansetmessages: + msg151268
2012-01-14 17:07:14jjdominguezmcreate