queuelogger: set thread name

Python 2.7 does not allow loading the cffi lib
inside the thread, but function calls are allowed

Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
This commit is contained in:
Timofey Titovets 2025-07-25 19:13:20 +02:00 committed by KevinOConnor
parent c78dd6a00a
commit 73c6674306

View File

@ -4,6 +4,7 @@
# #
# This file may be distributed under the terms of the GNU GPLv3 license. # This file may be distributed under the terms of the GNU GPLv3 license.
import logging, logging.handlers, threading, queue, time import logging, logging.handlers, threading, queue, time
import chelper
# Class to forward all messages through a queue to a background thread # Class to forward all messages through a queue to a background thread
class QueueHandler(logging.Handler): class QueueHandler(logging.Handler):
@ -25,11 +26,15 @@ class QueueListener(logging.handlers.TimedRotatingFileHandler):
def __init__(self, filename): def __init__(self, filename):
logging.handlers.TimedRotatingFileHandler.__init__( logging.handlers.TimedRotatingFileHandler.__init__(
self, filename, when='midnight', backupCount=5) self, filename, when='midnight', backupCount=5)
_, ffi_lib = chelper.get_ffi()
self._set_thread_name = ffi_lib.set_thread_name
self.bg_queue = queue.Queue() self.bg_queue = queue.Queue()
self.bg_thread = threading.Thread(target=self._bg_thread) self.bg_thread = threading.Thread(target=self._bg_thread)
self.bg_thread.start() self.bg_thread.start()
self.rollover_info = {} self.rollover_info = {}
def _bg_thread(self): def _bg_thread(self):
name_short = "queuelogger"[:15]
self._set_thread_name(name_short.encode('utf-8'))
while 1: while 1:
record = self.bg_queue.get(True) record = self.bg_queue.get(True)
if record is None: if record is None: