Skip to content

Commit c125c23

Browse files
committed
Fix import queue.Empty, fix task_done call on empty queue
1 parent 223a4d6 commit c125c23

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

python_logging_rabbitmq/compat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
if sys.version_info[0] == 2:
66
text_type = unicode
7-
from Queue import Queue as Queue
7+
from Queue import Queue as Queue, Empty as QueueEmpty
88
else:
99
text_type = str
10-
from queue import Queue as Queue
10+
from queue import Queue as Queue, Empty as QueueEmpty
1111

1212
try:
1313
import ujson as json # noqa: F401

python_logging_rabbitmq/handlers_oneway.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pika
88
from pika import credentials
99

10-
from .compat import Queue
10+
from .compat import Queue, QueueEmpty
1111
from .filters import FieldFilter
1212
from .formatters import JSONFormatter
1313
from .compat import ExceptionReporter
@@ -166,7 +166,7 @@ def message_worker(self):
166166
)
167167
)
168168

169-
except Queue.Empty:
169+
except QueueEmpty:
170170
continue
171171
except Exception:
172172
self.channel, self.connection = None, None
@@ -175,9 +175,10 @@ def message_worker(self):
175175
if self.stopping.is_set():
176176
self.stopped.set()
177177
break
178-
self.queue.task_done()
179-
if self.close_after_emit:
180-
self.close_connection()
178+
if not self.queue.empty():
179+
self.queue.task_done()
180+
if self.close_after_emit:
181+
self.close_connection()
181182
self.stopped.set()
182183

183184
def emit(self, record):

0 commit comments

Comments
 (0)