Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #27630
| From | sajuptpm <sajuptpm@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | psphere: how to make thread safe |
| Date | 2012-08-22 05:03 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <578d6c60-7b64-4d4e-9d38-4b26f9e4ad59@googlegroups.com> (permalink) |
Hi,
psphere: Python interface for the VMware vSphere Web Services SDK
I already developed an app using https://bitbucket.org/jkinred/psphere. But getting lot of errors since psphere is not thread safe (I think). So i wrote couple of scripts to test it (See attached files) and found that caching mechanism used by psphere is not thread safe. Could someone please give me some suggestion to make it thread safe.
=======Test Code ========
import psphere
from psphere.client import Client
from psphere.managedobjects import HostSystem, VirtualMachine, ComputeResource
client = Client("192.168.0.114", "root", "vmware1") ##vCenter
print "\nSucessfully connected to vCenter.\n"
from threading import Thread
def myfunc(i):
host1 = HostSystem.get(client, name="192.168.0.134")
host2 = HostSystem.get(client, name="192.168.0.113")
print "----i------",i
while True:
#host1.update(properties=["config", "vm"])
#host2.update(properties=["config", "vm"])
c = type(host1.config.network)
v = type(host2.config.network)
for vm in host1.vm:
k = vm.config.template
for vm in host2.vm:
p = vm.config.template
for i in range(10):
t = Thread(target=myfunc, args=(i,))
t.start()
"""
OUTPUT
=======
Sucessfully connected to vCenter.
----i------ 1
----i------ 3
----i------ 5
----i------ 0
----i------ 4
----i------ 2----i------ 7
----i------
9
----i------ 6
----i------ 8
Exception in thread Thread-4:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 504, in run
self.__target(*self.__args, **self.__kwargs)
File "vcenter_test1.py", line 19, in myfunc
k = vm.config.template
File "/home/saju/cvt/trunk/src/cvt/web/cvt/psphere/__init__.py", line 79, in __get__
value = self.fget(inst)
File "/home/saju/cvt/trunk/src/cvt/web/cvt/psphere/managedobjects.py", line 1236, in config
return self._get_dataobject("config", False)
File "/home/saju/cvt/trunk/src/cvt/web/cvt/psphere/__init__.py", line 116, in _get_dataobject
return self._cache[name][0]
KeyError: 'config'
Exception in thread Thread-6:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 504, in run
self.__target(*self.__args, **self.__kwargs)
File "vcenter_test1.py", line 17, in myfunc
v = type(host2.config.network)
AttributeError: VirtualMachineConfigInfo instance has no attribute 'network'
"""
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
psphere: how to make thread safe sajuptpm <sajuptpm@gmail.com> - 2012-08-22 05:03 -0700
Re: psphere: how to make thread safe Ramchandra Apte <maniandram01@gmail.com> - 2012-08-24 07:45 -0700
Re: psphere: how to make thread safe jonathan.kinred@gmail.com - 2012-08-26 05:45 -0700
Re: psphere: how to make thread safe jonathan.kinred@gmail.com - 2012-08-26 05:57 -0700
csiph-web