diff --git a/pubsub/google/cloud/pubsub_v1/futures.py b/pubsub/google/cloud/pubsub_v1/futures.py index f73893503301..067fc7429ab9 100644 --- a/pubsub/google/cloud/pubsub_v1/futures.py +++ b/pubsub/google/cloud/pubsub_v1/futures.py @@ -15,6 +15,7 @@ from __future__ import absolute_import import threading +import uuid import google.api_core.future from google.cloud.pubsub_v1.publisher import exceptions @@ -29,7 +30,11 @@ class Future(google.api_core.future.Future): This object should not be created directly, but is returned by other methods in this library. """ - _SENTINEL = object() + + # This could be a sentinel object or None, but the sentinel object's ID + # can change if the process is forked, and None has the possibility of + # actually being a result. + _SENTINEL = uuid.uuid4() def __init__(self): self._result = self._SENTINEL @@ -68,8 +73,8 @@ def done(self): This still returns True in failure cases; checking :meth:`result` or :meth:`exception` is the canonical way to assess success or failure. """ - return (self._exception is not self._SENTINEL or - self._result is not self._SENTINEL) + return (self._exception != self._SENTINEL or + self._result != self._SENTINEL) def result(self, timeout=None): """Return the message ID, or raise an exception. @@ -118,7 +123,7 @@ def exception(self, timeout=None): raise exceptions.TimeoutError('Timed out waiting for result.') # If the batch completed successfully, this should return None. - if self._result is not self._SENTINEL: + if self._result != self._SENTINEL: return None # Okay, this batch had an error; this should return it.