Skip to content

Instantly share code, notes, and snippets.

@raybotha
Created March 13, 2018 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raybotha/2d9d1119f1436ff34071d4ce3a041f51 to your computer and use it in GitHub Desktop.
Save raybotha/2d9d1119f1436ff34071d4ce3a041f51 to your computer and use it in GitHub Desktop.
Monkeypatched single thread
from google.cloud import pubsub_v1
from time import sleep
import eventlet
eventlet.monkey_patch()
publisher = pubsub_v1.PublisherClient()
topic_path = publisher.topic_path("project123", "topic123")
def process_message(msg):
publisher.publish(topic_path, data=msg.encode("utf-8"))
for i in range(1000):
process_message(str(i))
sleep(1)
@mattbennett
Copy link

You have to apply the monkey patch before imports, otherwise it doesn't take effect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment