From c5c79718a0cae83ccf943fb00264d3c97b52d334 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Tue, 19 Dec 2017 16:27:23 -0800 Subject: [PATCH 1/2] Use a UUID (rather than a sentinel object) for sentinel on Pub / Sub `Future`. --- pubsub/google/cloud/pubsub_v1/futures.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pubsub/google/cloud/pubsub_v1/futures.py b/pubsub/google/cloud/pubsub_v1/futures.py index f73893503301..8265b3125370 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 From b4a9d70a1e9cfeb88405047bd43e52e18e762884 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Tue, 19 Dec 2017 19:36:24 -0800 Subject: [PATCH 2/2] Changing identity check to equality check for Future._SENTINEL. --- pubsub/google/cloud/pubsub_v1/futures.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pubsub/google/cloud/pubsub_v1/futures.py b/pubsub/google/cloud/pubsub_v1/futures.py index 8265b3125370..067fc7429ab9 100644 --- a/pubsub/google/cloud/pubsub_v1/futures.py +++ b/pubsub/google/cloud/pubsub_v1/futures.py @@ -73,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. @@ -123,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.