I tried logging with multiprocessing, and found under windows, I will get different root logger in child process, but under Linux that is ok.
The test code:
main.py:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import multiprocessing
from mymod import func
def m_func():
server = multiprocessing.Process(target=func, args=())
server.start()
logger = logging.getLogger()
#print 'in global main: ', logger
if __name__ == '__main__':
print 'in main: ', logger
m_func()
mymod.py:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
logger = logging.getLogger()
# print 'in global func: ', logger
def func():
print 'in func: ', logger
Under Linux, the result is:
in main: <logging.RootLogger object at 0x10e4d6d90>
in func: <logging.RootLogger object at 0x10e4d6d90>
But under Windows 7, 64 bit, I will get different root logger between main and func:
in main: <logging.RootLogger object at 0x00000000021FFD68>
in func: <logging.RootLogger object at 0x00000000023BC898>
And If I initialize root logger in main scripts, how can I keep the settings such as level in child process under windows?
QueueHandler
only exists in python 3.x – Counterstroke