diff -r db661cee5baa Lib/concurrent/futures/__init__.py --- a/Lib/concurrent/futures/__init__.py Sat Jan 14 11:53:37 2012 +0100 +++ b/Lib/concurrent/futures/__init__.py Sat Jan 14 17:51:55 2012 +0100 @@ -13,6 +13,12 @@ Future, Executor, wait, - as_completed) + as_completed, + FUTURE_STATES, + PENDING, + RUNNING, + CANCELLED, + CANCELLED_AND_NOTIFIED, + FINISHED) from concurrent.futures.process import ProcessPoolExecutor from concurrent.futures.thread import ThreadPoolExecutor diff -r db661cee5baa Lib/concurrent/futures/_base.py --- a/Lib/concurrent/futures/_base.py Sat Jan 14 11:53:37 2012 +0100 +++ b/Lib/concurrent/futures/_base.py Sat Jan 14 17:51:55 2012 +0100 @@ -22,7 +22,7 @@ CANCELLED_AND_NOTIFIED = 'CANCELLED_AND_NOTIFIED' FINISHED = 'FINISHED' -_FUTURE_STATES = [ +FUTURE_STATES = [ PENDING, RUNNING, CANCELLED, @@ -274,12 +274,17 @@ done.update(waiter.finished_futures) return DoneAndNotDoneFutures(done, set(fs) - done) +Event = collections.namedtuple("Event", ["state", "timestamp"]) +Event.__doc__ = """Stores the timestamp at which a Future changed its state.""" + class Future(object): """Represents the result of an asynchronous computation.""" def __init__(self): """Initializes the future. Should not be called by clients.""" self._condition = threading.Condition() + self.__state = None + self.__history = [] self._state = PENDING self._result = None self._exception = None @@ -498,6 +503,27 @@ self._condition.notify_all() self._invoke_callbacks() + @property + def state(self): + """The current state of the future. It is one of FUTURE_STATES""" + return self.__state + + @property + def _state(self): + """Internal state property used also to store the state history + of the future""" + return self.__state + + @_state.setter + def _state(self, value): + self.__state = value + self.__history.append(Event(value, time.time())) + + @property + def history(self): + """The state history of the future. Return a list of Event objects""" + return self.__history + class Executor(object): """This is an abstract base class for concrete asynchronous executors."""

AltStyle によって変換されたページ (->オリジナル) /