[python-win32] com server instantiation mess

Mark Hammond mhammond at skippinet.com.au
Mon Nov 22 12:06:58 CET 2004


> > Von: Niki Spahiev [mailto:niki at vintech.bg]
> > try
> > self.logger=logging.getLogger('myloggerA')
> > for first object and
> > self.logger=logging.getLogger('myloggerB')
> > for second object
>
>
> I already did what you mean within my jscripts:

As Niki hinted, the issue is related purely to the Python logging module.

Try and re-create the issue in Python.  Ignore COM, and ignore any external
clients - pretend your application was purely Python:

> var Logger=new ActiveXObject("Bielo.Logger");

Instead of that, write a Python program with 2 threads, and each thread does
a:

import your_module
logger = your_module.loginterface()
logger.initialize("Bielo.Logger")

And you will find the exact same problem.

The reason is that each thread does:

logger=logging.getLogger('mylogger')
...
logger.addHandler(handler)

But, logging.getLogger() maintains a global set of loggers.  The second time
that the same process calls this code, you have a single logger object, but
with *two* handler objects added.  Each of these handlers prints the
message.

I've been burnt by this too :)

Mark



More information about the Python-win32 mailing list