AW: [python-win32] com server instantiation mess
Sprinzing, Thomas
Thomas.Sprinzing at bielomatik.de
Mon Nov 22 13:58:31 CET 2004
> As Niki hinted, the issue is related purely to the Python
> logging module.
>
<snip>
> 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 :)
D'oh. Who could have guessed that. So the loggers i create are global within
: an Application (=Task) or within a machine?
I guess the latter. (Didin't try yet)
Anyway, the fix was easily done:
def __init__(self):
import logging
import logging.handlers
import pythoncom
loggerid = str(pythoncom.CreateGuid())
self.logger=logging.getLogger(loggerid)
self.hdlr=''
self.logfile_size = 1048577
self.logfile_count = 10
self.formatter_string = '%(asctime)s %(message)s'
self.loglevel = logging.INFO
Every new instance gets its own loggerid. Works like a charm so far.
Thanks Mark & Niki
Thomas Sprinzing
More information about the Python-win32
mailing list