Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Closed
Description
Bug report
Bug description:
Common interface for getting an item from queue (queue.Queue, multiprocessing.Queue, etc.) is
defget(self,block=True,timeout=None): ...
but interpreters.Queue has a different one:
defget(self,timeout=None,*,_delay=10/1000): ...
This leads to incorrect behavior when used in logging.handlers.QueueListener. QueueListener thread exits ~1second after the queue becomes empty.
classQueueListener(object):defdequeue(self,block):returnself.queue.get(block)def_monitor(self): ...record=self.dequeue(True)# instead of blocking flag it sets the timeout for interpreters.Queue ...
Here's the test script
importsysimporttimeimportloggingfromlogging.handlersimportQueueHandler,QueueListenerfromconcurrent.futuresimportInterpreterPoolExecutor,waitfromconcurrent.interpretersimportcreate_queuedefinitworker(queue):loghandler=QueueHandler(queue)loghandler.setLevel(logging.DEBUG)logger=logging.getLogger()logger.setLevel(logging.DEBUG)logger.addHandler(loghandler)defworker(num:int,delay:float):time.sleep(delay)# emulate highloadlogging.debug('finish %s',str(num))classCustomQueueListener(QueueListener):defdequeue(self,block:bool)->logging.LogRecord:# return self.queue.get(block) # originalreturnself.queue.get()defcheck(listener:QueueListener,bounds:tuple[int,int],delay:float):tasks= []with (InterpreterPoolExecutor(initializer=initworker,initargs=(queue, ))aspool,listener, ):foriinrange(*bounds):tasks.append(pool.submit(worker,i,delay))wait(tasks)if__name__=='__main__':loghandler=logging.StreamHandler(sys.stdout)queue=create_queue()check(QueueListener(queue,loghandler), (0,10),delay=0.5)# everything is okqueue=create_queue()check(QueueListener(queue,loghandler), (10,20),delay=1.25)# no output, because listener thread is stoppedqueue=create_queue()check(CustomQueueListener(queue,loghandler), (20,30),delay=1.25)# everything is ok
CPython versions tested on:
3.14
Operating systems tested on:
Windows, Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status
Done
Status
Done