Modify termination
This commit is contained in:
@@ -72,8 +72,6 @@ class LiveChat:
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
_setup_finished = False
|
_setup_finished = False
|
||||||
#チャット監視中のListenerのリスト
|
|
||||||
_listeners = []
|
|
||||||
|
|
||||||
def __init__(self, video_id,
|
def __init__(self, video_id,
|
||||||
seektime=0,
|
seektime=0,
|
||||||
@@ -103,19 +101,13 @@ class LiveChat:
|
|||||||
self._parser = Parser(is_replay=self._is_replay)
|
self._parser = Parser(is_replay=self._is_replay)
|
||||||
self._pauser = Queue()
|
self._pauser = Queue()
|
||||||
self._pauser.put_nowait(None)
|
self._pauser.put_nowait(None)
|
||||||
self._setup()
|
|
||||||
self._first_fetch = True
|
self._first_fetch = True
|
||||||
self._fetch_url = "live_chat/get_live_chat?continuation="
|
self._fetch_url = "live_chat/get_live_chat?continuation="
|
||||||
self._topchat_only = topchat_only
|
self._topchat_only = topchat_only
|
||||||
self._logger = logger
|
self._logger = logger
|
||||||
LiveChat._logger = logger
|
|
||||||
if not LiveChat._setup_finished:
|
|
||||||
LiveChat._setup_finished = True
|
|
||||||
if interruptable:
|
if interruptable:
|
||||||
signal.signal(signal.SIGINT, (lambda a, b:
|
signal.signal(signal.SIGINT, lambda a, b: self.terminate())
|
||||||
(LiveChat.shutdown(None,signal.SIGINT,b))
|
self._setup()
|
||||||
))
|
|
||||||
LiveChat._listeners.append(self)
|
|
||||||
|
|
||||||
def _setup(self):
|
def _setup(self):
|
||||||
# direct modeがTrueでcallback未設定の場合例外発生。
|
# direct modeがTrueでcallback未設定の場合例外発生。
|
||||||
@@ -174,7 +166,8 @@ class LiveChat:
|
|||||||
}
|
}
|
||||||
time_mark = time.time()
|
time_mark = time.time()
|
||||||
if self._direct_mode:
|
if self._direct_mode:
|
||||||
processed_chat = self.processor.process([chat_component])
|
processed_chat = self.processor.process(
|
||||||
|
[chat_component])
|
||||||
if isinstance(processed_chat, tuple):
|
if isinstance(processed_chat, tuple):
|
||||||
self._callback(*processed_chat)
|
self._callback(*processed_chat)
|
||||||
else:
|
else:
|
||||||
@@ -319,14 +312,7 @@ class LiveChat:
|
|||||||
'''
|
'''
|
||||||
Listenerを終了する。
|
Listenerを終了する。
|
||||||
'''
|
'''
|
||||||
|
if self.is_alive():
|
||||||
self._is_alive = False
|
self._is_alive = False
|
||||||
if self._direct_mode == False:
|
self._buffer.put({})
|
||||||
#bufferにダミーオブジェクトを入れてis_alive()を判定させる
|
self._logger.info(f'[{self.video_id}]終了しました')
|
||||||
self._buffer.put({'chatdata':'','timeout':0})
|
|
||||||
self._logger.info(f'[{self.video_id}]finished.')
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def shutdown(cls, event, sig = None, handler=None):
|
|
||||||
cls._logger.debug("shutdown...")
|
|
||||||
for t in LiveChat._listeners:
|
|
||||||
t._is_alive = False
|
|
||||||
|
|||||||
Reference in New Issue
Block a user