pyvmomi icon indicating copy to clipboard operation
pyvmomi copied to clipboard

Is pyvmomi service instance thread-safe?

Open sidlovskyy opened this issue 6 years ago • 1 comments

Hi,

I am using SmartConnectNoSSL to connect to my server. May I use si (service instance) returned in multithreading environment sharing the same instance of si (e.g. may I load metrics from different resources in parallel). May there be any issues with vSphere API because of the same session parallel calls?

Thanks

sidlovskyy avatar Dec 16 '19 17:12 sidlovskyy

Most operations should be safe by reusing the same si, which is the same session/cookie. But if you are using the property collector (si.content.propertyCollector), then that will be shared among all the clients of si. In that case, you should create/destroy one explicitly:

pc = si.content.propertyCollector.CreatePropertyCollector()
...
pc.Destroy()

There might be other gotchas to using the same session, but I think that is the main one that I noticed.

prziborowski avatar Dec 19 '19 20:12 prziborowski