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

Use a UUID (rather than a sentinel object) for sentinel on Pub / Sub Future. #4634

Merged
merged 2 commits into from
Dec 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pubsub/google/cloud/pubsub_v1/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down