问题
I am using google cloud PubSub and was wondering whether google.cloud.pubsub_v1.PublisherClient
was thread safe. Do I need to pass a new instance of this object to each threading.Thread
or is it safe to share the same instance across threads?
回答1:
It depends on the client library you are using.
This Python client library is not thread safe due to being built on top of the httplib2 library, which is not thread-safe. But, as the first link says, this is an old library. The newer Python library for Pub/Sub is thread safe.
Other Google client libraries are "thread safe" too. The .NET one, for example, was bult with the convention in mind that all static members should be thread-safe.
来源:https://stackoverflow.com/questions/52659169/is-google-cloud-pubsub-v1-publisherclient-thread-safe