Help, pls: COM local server factory class

Mark Hammond MarkH at ActiveState.com
Mon Jun 18 22:53:15 EDT 2001


Bill Bell wrote:

> Esteemed Pythonistas:
> 
> The code that appears below is intended to define a COM local 
> server. (My understanding of some earlier messages on this list is 
> that it should result in a singleton by default.)


Nope.  No singleton here.  Each client creating your COM object gets a 
brand new instance of your "COMServer" class - and hence a brand new GUI 
thread.

As it is a local server, you could store the GUI objects in a global - 
then each process will be able to have a single GUI thread and object 
that could be shared by many instances of the COM object.

Of course, if you know that each process will only ever create a single 
COM object, then you can just use what you have - until someone creates 
a second :)

Eeek - I just re-read your code.  It does looks basically correct - 
however, in this case you should drop most COM stuff from "class 
COMServer".  Drop all "_reg_" attributes, and do not attempt to register 
this class.  This means that it will not be possible to create the 
COMServer object directly, and _must_ go via the factory which does 
implement the singleton behaviour.  Note however that this will still 
only be a "per-process" singleton - but you have no real choice about 
that considering you are using GUI features.

> 2. What is the meaning of the following?
...

>   File "<COMObject WebPASS.ServerFactory1>", line 2, in Factory
> com_error: (-2147352567, 'Exception occurred.', (0, 'Python COM 
> Server Internal Error', 'Unexpected Python Error: 
> exceptions.TypeError: Objects for SAFEARRAYS must be 
> sequences (of sequences), or a buffer object.', None, 0, -
> 2147467259), None)


Probably that as part of your code, you are calling out to _another_ COM 
object.  This other COM object has a prototype that wants a SAFEARRAY, 
and is therefore expecting a Python list or tuple.

You should register your server for debugging.  eg "MyServer.py 
--debug".  Then startup Pythonwin's "Tools->Collect Remote Debugging 
Output" option.  You should then see a complete traceback pointing to 
the specific line that fails.


Hope this helps...

Mark.




More information about the Python-list mailing list