You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 9, 2026. It is now read-only.
Sample code for a subscriber from Google's guide with minor changes that will show my issue:
fromconcurrent.futuresimportTimeoutErrorfromgoogle.cloudimportpubsub_v1fromtimeimportsleep# TODO(developer)# project_id = "your-project-id"# subscription_id = "your-subscription-id"# Number of seconds the subscriber should listen for messages# timeout = 5.0subscriber=pubsub_v1.SubscriberClient()
# The `subscription_path` method creates a fully qualified identifier# in the form `projects/{project_id}/subscriptions/{subscription_id}`subscription_path=subscriber.subscription_path(project_id, subscription_id)
defcallback(message):
print(f"Received {message}.")
sleep(30)
message.ack()
print("Acked")
streaming_pull_future=subscriber.subscribe(subscription_path, callback=callback)
print(f"Listening for messages on {subscription_path}..\n")
# Wrap subscriber in a 'with' block to automatically call close() when done.withsubscriber:
sleep(10)
streaming_pull_future.cancel()
streaming_pull_future.result()
I expect this code to stop pulling messages and finish the running messages and then exits.
Actually this code stops pulling messages and finish executing the running messages but it does not ack the messages. The .ack() happens but the server does not receive the ack, so next run the same messages return again.
Hey,
Environment details
google-cloud-pubsubversion: 2.2.0Code example
Sample code for a subscriber from Google's guide with minor changes that will show my issue:
From https://cloud.google.com/pubsub/docs/pull
I expect this code to stop pulling messages and finish the running messages and then exits.
Actually this code stops pulling messages and finish executing the running messages but it does not ack the messages. The .ack() happens but the server does not receive the ack, so next run the same messages return again.
Why doesn't the server receives the ack?
How to gracefully shutdown the subscriber?
What is the expected behavior of .cancel()?
Corresponding stackoverflow question:
https://stackoverflow.com/questions/65761254/pub-sub-python-client-gracefully-shutdown-subscriber
Thank you!