mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Bugfix close async log handler (#5086)
This commit is contained in:
parent
a2f17cccbb
commit
0ecd185f0d
@ -55,18 +55,11 @@ class AsyncHandler(object):
|
||||
|
||||
When blocking=True, will wait till closed.
|
||||
"""
|
||||
if not self._thread.is_alive():
|
||||
return
|
||||
yield from self._queue.put(None)
|
||||
|
||||
if blocking:
|
||||
# Python 3.4.4+
|
||||
# pylint: disable=no-member
|
||||
if hasattr(self._queue, 'join'):
|
||||
yield from self._queue.join()
|
||||
else:
|
||||
while not self._queue.empty():
|
||||
yield from asyncio.sleep(0, loop=self.loop)
|
||||
while self._thread.is_alive():
|
||||
yield from asyncio.sleep(0, loop=self.loop)
|
||||
|
||||
def emit(self, record):
|
||||
"""Process a record."""
|
||||
@ -85,23 +78,15 @@ class AsyncHandler(object):
|
||||
|
||||
def _process(self):
|
||||
"""Process log in a thread."""
|
||||
support_join = hasattr(self._queue, 'task_done')
|
||||
|
||||
while True:
|
||||
record = run_coroutine_threadsafe(
|
||||
self._queue.get(), self.loop).result()
|
||||
|
||||
# pylint: disable=no-member
|
||||
|
||||
if record is None:
|
||||
self.handler.close()
|
||||
if support_join:
|
||||
self.loop.call_soon_threadsafe(self._queue.task_done)
|
||||
return
|
||||
|
||||
self.handler.emit(record)
|
||||
if support_join:
|
||||
self.loop.call_soon_threadsafe(self._queue.task_done)
|
||||
|
||||
def createLock(self):
|
||||
"""Ignore lock stuff."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user