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