1

I am currently using Google pub/sub and using the Google pubsub python library. I can't find a way to limit the number of threads spawned on my machine which uses most of my resources.

Here's my code:

def publish(data):
  def callback(message_future):
    if message_future.exception(timeout=3):
      self.logger.error('Publishing message on {} threw an Exception {}.'.format(topic_name, message_future.exception()))

  data = data.encode('utf-8')
  message_future = self.publisher.publish(topic_path, data=data)
  message_future.add_done_callback(callback)
Dinesh
  • 11
  • 1
  • I'm very poor on Python ... but maybe after performing the publish, you can call the wait() function as documented here https://docs.python.org/3/library/concurrent.futures.html#module-functions This appears to allow us to block waiting for the publish to have completed. You would thus be serializing one publish after another. – Kolban Oct 04 '18 at 23:03

0 Answers0