[python-win32] Creating a COM singleton

Jens B. Jorgensen jens.jorgensen at tallan.com
Thu Feb 3 17:41:55 CET 2005


Jim McCoy wrote:

>Argh!  Well, it turns out that the real problem was that when creating
>a mutex for a module-level singleton you should not store a ref to the
>handle in an instance that might find itself getting popped.  Assign
>to a class variable that will stick.  D'oh!
>
>I will take a look at setting up the COM object as a service.  One
>question that pops up is whether such a service would run "as the
>local user"?  We use the COM service as an authentication bridge
>between an agent service that is always running in the background (but
>runs as the admin) and various users on the system.  Hmmm, something
>to check out.
>  
>
Yes, this can be a problem. It's not strictly necessary of course to run 
as a service. The process could just ensure that once it starts it stays 
around. Then you'd have a question of when the process should go out of 
scope. In any case the key thing is to make sure that that class object 
stays registered with the SCM so it can be re-used. Then the class 
object itself needs to return the same object. It may be easier to have 
2 different objects. One COM object would be the 'factory' object that 
would return a reference to the singleton class. Or, perhaps you're 
already doing this. That way you can control the creation of the 
singleton object in your own code.

-- 
Jens B. Jorgensen
jens.jorgensen at tallan.com

"With a focused commitment to our clients and our people, we deliver value through customized technology solutions"  

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2861 bytes
Desc: S/MIME Cryptographic Signature
Url : http://mail.python.org/pipermail/python-win32/attachments/20050203/c583479a/smime.bin


More information about the Python-win32 mailing list