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

Konstantin Veretennicov kveretennicov at
Fri Jun 25 16:12:58 CEST 2004

google at (Paul Keating) wrote in message news:<51f8958a.0406240327.1b26a76f at>...
> 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

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 

    import win32com.client

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

    Dim A As Object
    Set A = CreateObject("Arena.Security")
    Dim V As Variant
    Let V = A.GetProfileComponentMatrixEx()

More information about the Python-list mailing list