简体   繁体   English

Python 的 SOAPpy 库是线程安全的吗?

[英]Is Python's SOAPpy library threadsafe?

How thread safe is the SOAPpy library for Python? Python 的 SOAPpy 库的线程安全性如何? I'm finding the documentation non-existent and no mention of thread safety (for or against) anywhere.我发现文档不存在,并且在任何地方都没有提到线程安全(支持或反对)。

Specifically, can threads share a SOAPpy.SOAPProxy object, calling different RPCs ?具体来说,线程可以共享一个 SOAPpy.SOAPProxy object,调用不同的 RPC吗? eg,例如,

client = SOAPpy.SOAPProxy(url)
thread1: client.MyFunc()
thread2: client.MyFunc()

Without ill-effects?没有不良影响?

Additionally, is the construction of the proxy objects expensive ?此外,代理对象的构建是否昂贵

SOAPpy.SOAPProxy doesn't appear to be thread-safe at first glance. SOAPpy.SOAPProxy似乎不是线程安全的。 In the version 0.12.0 __call method, there is an assignment ( Client.py line 360):在 0.12.0 版本的__call方法中,有一个赋值( Client.py第 360 行):

        r, self.namespace = self.transport.call(self.proxy, m, ns, sa,
                                                encoding = self.encoding,
                                             http_proxy = self.http_proxy,
                                                config = self.config)

So if client.MyFunc() is invoked from 2 different threads, they will create separate connections but will both assign a value to the self.namespace attribute.因此,如果从 2 个不同的线程调用client.MyFunc() ,它们将创建单独的连接,但都会为self.namespace属性分配一个值。

On the plus side, constructing an instance of SOAPProxy for each thread should be quite efficient.从好的方面来说,为每个线程构造一个 SOAPProxy 实例应该非常有效。 I was able to create 100 instances in ~1ms on a virtual machine, which should be small compared to a SOAP request round-trip time.我能够在大约 1 毫秒内在虚拟机上创建 100 个实例,与 SOAP 请求往返时间相比应该很小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM