470,826 Members | 2,363 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,826 developers. It's quick & easy.

Python COM - limit on size/complexity of returned object?

I have a very simple COM server written in Python that is trying to
return a two-dimensional array 268 x 20. The values it contains are
some small integers, some short (<29 character) Unicode strings, and
None.

To isolate the problem I have taken out the code that builds the
matrix from real data, and just substituted a literal tuple of tuples,
like this:

class AtlasSecurity:
_reg_progid_ = 'Arena.Security'
...
def GetProfileComponentMatrixEx(self):
# self.BuildMatrix()
self.matrix = ((u'ID', u'Name', u'Type', .... ),
... )) # a 268-tuple of 20-tuples
self.last_result = (self.matrix,)
return self.last_result

Because I was having trouble calling it from Excel ("the server has
disconnected from its clients"), to see what was going on I decided to
call it from a Python client, like this:

from win32com.client import Dispatch
x = Dispatch("Arena.Security")
print x.GetProfileComponentMatrixEx()

This blows up in python22.dll with a C++ Runtime abort(), no matter
what I try. I can write a method that I can call 268 times to return
the data one 20-element vector at a time. This works, but is really
only good for simple data structures and I need this to work with
structures of arbitrary complexity and levels of nesting.

Is there a restriction on the size or complexity of the SafeArray that
pythoncom is constructing from the returned value? Or what else am I
doing wrong?

(I am using Python 2.2 because I am working with embedded Python and
that is the version that is embedded.)
Jul 18 '05 #1
3 1786
Hi !

Only for size (because I don't understand correctly english).

I had a COM-server, in Python. And I send/read string of 5-10MB size,
without pb (perhaps time had few seconds in excess).

@-salutations
--
Michel Claveau
mél : http://cerbermail.com/?6J1TthIa8B
sites : http://mclaveau.com http://bergoiata.org http://ponx.org

Jul 18 '05 #2
go****@prodigycomputing.com (Paul Keating) wrote in message news:<51**************************@posting.google. com>...
I have a very simple COM server written in Python that is trying to
return a two-dimensional array 268 x 20. The values it contains are
some small integers, some short (<29 character) Unicode strings, and
None.

To isolate the problem I have taken out the code that builds the
matrix from real data, and just substituted a literal tuple of tuples,
like this:

class AtlasSecurity:
_reg_progid_ = 'Arena.Security'
...
def GetProfileComponentMatrixEx(self):
# self.BuildMatrix()
self.matrix = ((u'ID', u'Name', u'Type', .... ),
... )) # a 268-tuple of 20-tuples
self.last_result = (self.matrix,)
return self.last_result

Because I was having trouble calling it from Excel ("the server has
disconnected from its clients"), to see what was going on I decided to
call it from a Python client, like this:

from win32com.client import Dispatch
x = Dispatch("Arena.Security")
print x.GetProfileComponentMatrixEx()

This blows up in python22.dll with a C++ Runtime abort(), no matter
what I try. I can write a method that I can call 268 times to return
the data one 20-element vector at a time. This works, but is really
only good for simple data structures and I need this to work with
structures of arbitrary complexity and levels of nesting.

Is there a restriction on the size or complexity of the SafeArray that
pythoncom is constructing from the returned value? Or what else am I
doing wrong?

(I am using Python 2.2 because I am working with embedded Python and
that is the version that is embedded.)


Well, I did some testing with python 2.3 (that's what I have).
Not sure if it will cheer you up, but I had no problems.

- kv
<server-code>
class AtlasSecurity:
_reg_clsid_ = '{92522CC6-05A5-4172-BFCA-56C65FD45467}'
_reg_desc_ = 'Arena Server'
_reg_progid_ = 'Arena.Security'

_public_methods_ = ['GetProfileComponentMatrixEx']
_public_attrs_ = []
_readonly_attrs_ = []

def GetProfileComponentMatrixEx(self):
self.matrix = ((u'ID', u'Name', u'Type') * 10,) * 268
self.last_result = (self.matrix,)
return self.last_result
if __name__ == '__main__':
import win32com.server.register
win32com.server.register.UseCommandLine(AtlasSecur ity)
</server-code>
<python-client-code>
import win32com.client

from win32com.client import Dispatch
x = Dispatch("Arena.Security")
print x.GetProfileComponentMatrixEx()
</python-client-code>

<vb-client-code>
Dim A As Object
Set A = CreateObject("Arena.Security")

Dim V As Variant
Let V = A.GetProfileComponentMatrixEx()
</vb-client-code>
Jul 18 '05 #3
kv***********@yahoo.com (Konstantin Veretennicov) wrote in message news:<51**************************@posting.google. com>...
Well, I did some testing with python 2.3 (that's what I have).
Not sure if it will cheer you up, but I had no problems.


Thanks for the pointer. I tried it on another machine with 2.3 and
that works with no problems.

And I made some further discoveries on the 2.2 side: the problem isn't
a limit on the size of the returned object, it's cumulative. I amended
GetProfileComponentMatrixEx() to return the first n rows of the
matrix, to find out what the limit was: like this
print len(GetProfileComponentMatrixEx(10)) 10 print len(GetProfileComponentMatrixEx(40)) 40 print len(GetProfileComponentMatrixEx(80)) <GPF!>
But trying it repeatedly I found that I could only execute the
following line once: it crashed calling it with an argument of 40 the
second time: print len(GetProfileComponentMatrixEx(40)) 40 print len(GetProfileComponentMatrixEx(40)) <GPF!>
And then I tried this repeatedly: print len(GetProfileComponentMatrixEx(10))

and -- surprise! -- it failed about the 7th or 8th invocation.

So, now there are two possibilities.
1. It's a 2.2 problem that is fixed in 2.3 (though I looked in
Sourceforge for the bug reports and this did not show up there).
2. It's a side-effect of the module I'm importing to do the actual
work. On the machine running 2.3, I had to write a stub to represent
this module, because it is a home machine that can't see the work
server where the data is.

If the DLL is at fault, I'm going to have a hard time convincing the
vendor that they have to fix it. If I were them, I'd be sceptical. The
DLL is loaded by the import statement, but in this test it is never
called. It's hard to see what it's initialization code could possibly
be doing to break pythoncom.
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Allison Bailey | last post: by
699 posts views Thread by mike420 | last post: by
65 posts views Thread by Amol Vaidya | last post: by
267 posts views Thread by Xah Lee | last post: by
17 posts views Thread by frederic.pica | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.