Closed zxfzqf closed 5 years ago
I try use MultiProcessingHandler ,but it lost data, Is it wrong for me to use the method?
import os
import time
import datetime
import logbook
from multiprocessing import Pool
from multiprocessing import Queue
from logbook import Logger, FileHandler, TimedRotatingFileHandler
from logbook.queues import MultiProcessingHandler, MultiProcessingSubscriber
queue = Queue(-1)
handler_tag = MultiProcessingHandler(queue)
handler_tag.push_application()
logger = Logger()
target_handlers = logbook.NestedSetup([
logbook.NullHandler(),
logbook.FileHandler('file_log.log', mode='a', level=logbook.DEBUG)
])
sub = MultiProcessingSubscriber(queue)
c = sub.dispatch_in_background(target_handlers)
def process_log(p_off):
for x in range(0, 100):
d = datetime.datetime.now()
t_str = 'testtest%d'%x
logger.warning('{}:{}:p_off({}):pid({})'.format(t_str, d.strftime('%Y-%m-%d %H:%M:%S'), p_off, os.getpid()))
if __name__ == '__main__':
logger.info('start.....')
p = Pool(4)
for i in range(4):
p.apply_async(process_log, args=(i,))
print('waiting.....')
p.close()
p.join()
print('done.....')
use MultiProcessingHandler code at linux is work .win10 …… Can anyone solve my problem?
TaggingHandler ....,It still doesn't work.. I didn't find an example of work.
no one responded to me.
depressed……
call it quits
OS:window 10 python version:3.6
I want different levels of logging to be saved to different files. I use TaggingHandler, but it not work, I was wrong?What do I need to do?