Difference between revisions of "ZSI Notes"

From PeformIQ Upgrade
Jump to navigation Jump to search
Line 195: Line 195:


</pre>
</pre>
==ZSI Thread Safe?==
<pre>
I don't think so but threads in python are restricted by the GIL so 
all state is shared between threads.  So if you're changing an objects 
state all threads will "instantly" see it.  This is up to you to manage.
-josh
On May 14, 2008, at 12:56 AM, Esteban wrote:
> After some testing, I confirmed that I cannot share the same
> ServicePort on different clients as it is not thread safe (I expected
> this result actually...)
>
> Using a different one for each client seems to work. However, I am
> concerned about race conditions that are difficult to detect. Does
> somebody know whether the servicePorts share any resources that could
> lead to the wrong result if accessing through several threads?
>
> Thanks,
> -- Esteban.
>
> On May 13, 10:01 am, Esteban <robe...@gmail.com> wrote:
>> Hi there,
>>
>> I am writting a client for a Web Service using ZSI 2.0.
>> I have to poll different operations on the same service, using
>> different time intervals.
>> I'd like to use a separate thread for each operation, so that one of
>> them can execute while others are either sleeping or blocked waiting
>> for the service's response.
>>
>> Is the service binding returned by
>> ServiceLocator().getServicePort(url, **kw) thread safe (so that it 
>> can
>> be shared by all client threads)? In case it is not, would it be any
>> problem if I create a different service  locator as above on each
>> thread? I am not sure if they would share any common stuff in
>> downstream...
>>
>> I read a similar post (http://groups.google.com/group/pywebsvcs/
>> browse_thread/thread/cf77b338ccb1e526/26a4e4dcfec57564?
>> lnk=gst&q=thread#26a4e4dcfec57564)
>> but I did not really get it clear and I think it was more focused on
>> the service side (as it talked about Apache for example).
>>
>> Any other suggestion to approach this problem are appreciated ;)
>>
>> Thanks for your help,
>> -- Esteban
>>
</pre>
[[Category:Python]]
[[Category:Python]]
[[Category:ZSI]]
[[Category:ZSI]]

Revision as of 09:29, 23 May 2008

Some Notes from Pywebsvcs-talk@lists.sourceforge.net List

My scrapbook of notes and extracts from the Pywebsvcs mailing list...

alphabetical order of 'self.attribute_typecode_dict'

This should be irrelevant, although order is important for canonicalization for an entirely different matter.

I think you could retain your ordering by replacing the underlying dict with your own dict subclass that maintains a list too.

	Topic._attrs = OrderDict()


Something like Collection, although obviously this is a bit old.

from ZSI.wstools.Utility import Collection

class Collection(UserDict):
     """Helper class for maintaining ordered named collections."""
     default = lambda self,k: k.name
     def __init__(self, parent, key=None):
         UserDict.__init__(self)
         self.parent = weakref.ref(parent)
         self.list = []
         self._func = key or self.default

     def __getitem__(self, key):
         if type(key) is type(1):
             return self.list[key]
         return self.data[key]

     def __setitem__(self, key, item):
         item.parent = weakref.ref(self)
         self.list.append(item)
         self.data[key] = item

     def keys(self):
         return map(lambda i: self._func(i), self.list)

     def items(self):
         return map(lambda i: (self._func(i), i), self.list)

     def values(self):
         return self.list

Newbie Stuff

Upgrade to ZSI-2.1a and this package is no longer required.

-josh


On May 14, 2008, at 4:02 PM, freeav8r wrote:

> Hi all:
>
> I’m new to ZSI and apache and I’m having
> difficulty getting my first ZSI web service up and
> running.
>
> I installed apache with no problems and also installed
> mod_python.  I ran the mod_python “hello world”
> test by changing the httpd.conf file with the
> following entry:
>
> <Directory "C:/Program Files/Apache Software
> Foundation/Apache2.2/htdocs/test">
>   AddHandler mod_python .py
>   PythonHandler mptest
>   PythonDebug On
> </Directory>
>
> The “Hello world” worked fine.
>
> I tried the mod_python example (2.1.3) found here:
> http://pywebsvcs.sourceforge.net/zsi.html
>
> Because of the apache config entry above, I created
> the following to files with the below names:
>
> ========== mptest.py =========
> from ZSI import dispatch
> from mod_python import apache
>
> import MyHandler
> mod = __import__('encodings.utf_8', globals(),
> locals(), '*')
> mod = __import__('encodings.utf_16_be', globals(),
> locals(), '*')
>
> def handler(req):
>    dispatch.AsHandler(modules=(MyHandler,),
> request=req)
>    return apache.OK
> ========== end mptest.py =======
>
> =========MyHandler.py ========
> def hello():
>    return "Hello, world"
>
> def echo(*args):
>    return args
>
> def average(*args):
>    sum = 0
>    for i in args: sum += i
>    return sum / len(args)
> ========= end MyHandler.py ========
>
> When I request the mptest.py file I get the following
> error:
>
>
>  File "C:\Program
> Files\Python25\Lib\site-packages\ZSI\parse.py", line
> 54, in __init__
>    from xml.dom.ext.reader import PyExpat
>
> ImportError: No module named ext.reader
>
> I'm running python 2.5 and the lastest stable versions
> of apache, mod_python, and ZSI.
>
>
> Any ideas?
>
> -freeav8r

http persistent connection

I think you can do this by using your own transport.

Here is the relevant code from client.py:

         self.h = transport(netloc, None, **self.transdict)
         self.h.connect()
         self.SendSOAPData(soapdata, url, soapaction, **kw)


So basically you'd need something like a Singleton that delegates to  
actual transports, so you can maintain these instances between soap  
calls and reuse the same transport when appropriate.

But I'm not sure about the rest, you'll need a transport that  
implements HTTP persistent connections.  Maybe twisted is a better bet  
than the python httplib.

-josh


On May 17, 2008, at 2:52 PM, Kleber Carriello de Oliveira wrote:

> Sirs,
>
> I'm trying to use ZSI with http persistent connection, does anyone  
> know if it's possible? If yes can you send me one example?
>
> My problem is that I need to call one API about 500 times per  
> second... I believe that using persistent connection I can reach  
> this number instead of open and close one tcp connection each time I  
> do a call.
>
> Thanks in advance,
>
> Kleber Carriello
>
>
>      Abra sua conta no Yahoo! Mail, o único sem limite de espaço  
> para armazenamento!
> http://br.mail.yahoo.com/

ServiceProxy

> server = ServiceProxy(w, pyclass=True, tracefile=sys.stdout)

ZSI 2.0.0 as a whole supports complex type, but there's a serious bug
in ServiceProxy in 2.0.0 which prevents using it with asdict=False
(ServiceProxy in 2.0.0 doesn't have the pyclass keyword) [1]. I
suggest upgrading to 2.1a1 where the broken part of ServiceProxy has
been rewritten and now works.

[1] Specifically ServiceProxy._call always passes args or kwargs
through to binding.Send regardless of what asdict is set to, so that
with complex types calls to proxy methods complain that binding.Send
is getting tuples (i.e. args) or dicts (i.e. kwargs) instead of the
expected complex types.

ZSI Thread Safe?

I don't think so but threads in python are restricted by the GIL so  
all state is shared between threads.  So if you're changing an objects  
state all threads will "instantly" see it.  This is up to you to manage.

-josh


On May 14, 2008, at 12:56 AM, Esteban wrote:

> After some testing, I confirmed that I cannot share the same
> ServicePort on different clients as it is not thread safe (I expected
> this result actually...)
>
> Using a different one for each client seems to work. However, I am
> concerned about race conditions that are difficult to detect. Does
> somebody know whether the servicePorts share any resources that could
> lead to the wrong result if accessing through several threads?
>
> Thanks,
> -- Esteban.
>
> On May 13, 10:01 am, Esteban <robe...@gmail.com> wrote:
>> Hi there,
>>
>> I am writting a client for a Web Service using ZSI 2.0.
>> I have to poll different operations on the same service, using
>> different time intervals.
>> I'd like to use a separate thread for each operation, so that one of
>> them can execute while others are either sleeping or blocked waiting
>> for the service's response.
>>
>> Is the service binding returned by
>> ServiceLocator().getServicePort(url, **kw) thread safe (so that it  
>> can
>> be shared by all client threads)? In case it is not, would it be any
>> problem if I create a different service  locator as above on each
>> thread? I am not sure if they would share any common stuff in
>> downstream...
>>
>> I read a similar post (http://groups.google.com/group/pywebsvcs/
>> browse_thread/thread/cf77b338ccb1e526/26a4e4dcfec57564?
>> lnk=gst&q=thread#26a4e4dcfec57564)
>> but I did not really get it clear and I think it was more focused on
>> the service side (as it talked about Apache for example).
>>
>> Any other suggestion to approach this problem are appreciated ;)
>>
>> Thanks for your help,
>> -- Esteban
>>