Fix termination of fetching chat data
This commit is contained in:
@@ -65,7 +65,7 @@ class LiveChat:
|
||||
_listeners= []
|
||||
def __init__(self, video_id,
|
||||
processor = DefaultProcessor(),
|
||||
buffer = Buffer(maxsize = 20),
|
||||
buffer = None,
|
||||
interruptable = True,
|
||||
callback = None,
|
||||
done_callback = None,
|
||||
@@ -145,8 +145,8 @@ class LiveChat:
|
||||
|
||||
def _listen(self, continuation):
|
||||
''' continuationに紐付いたチャットデータを取得し
|
||||
BUfferにチャットデータを格納、
|
||||
次のcontinuaitonを取得してループする
|
||||
Bufferにチャットデータを格納、
|
||||
次のcontinuaitonを取得してループする。
|
||||
|
||||
Parameter
|
||||
---------
|
||||
@@ -178,9 +178,11 @@ class LiveChat:
|
||||
time.sleep(diff_time)
|
||||
continuation = metadata.get('continuation')
|
||||
except ChatParseException as e:
|
||||
logger.info(f"{str(e)}(video_id:\"{self.video_id}\")")
|
||||
self.terminate()
|
||||
logger.error(f"{str(e)}(video_id:\"{self.video_id}\")")
|
||||
return
|
||||
except (TypeError , json.JSONDecodeError) :
|
||||
self.terminate()
|
||||
logger.error(f"{traceback.format_exc(limit = -1)}")
|
||||
return
|
||||
|
||||
@@ -209,6 +211,7 @@ class LiveChat:
|
||||
else:
|
||||
logger.error(f"[{self.video_id}]"
|
||||
f"Exceeded retry count. status_code={status_code}")
|
||||
self.terminate()
|
||||
return None
|
||||
return livechat_json
|
||||
|
||||
@@ -257,18 +260,10 @@ class LiveChat:
|
||||
if self._direct_mode == False:
|
||||
#bufferにダミーオブジェクトを入れてis_alive()を判定させる
|
||||
self._buffer.put({'chatdata':'','timeout':1})
|
||||
logger.info(f'終了しました:[{self.video_id}]')
|
||||
logger.info(f'[{self.video_id}]終了しました')
|
||||
|
||||
@classmethod
|
||||
def shutdown(cls, event, sig = None, handler=None):
|
||||
logger.debug("シャットダウンしています")
|
||||
for t in LiveChat._listeners:
|
||||
t._is_alive = False
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
t._is_alive = False
|
||||
@@ -18,9 +18,8 @@ from ..processors.default.processor import DefaultProcessor
|
||||
from ..processors.combinator import Combinator
|
||||
|
||||
logger = config.logger(__name__)
|
||||
MAX_RETRY = 10
|
||||
headers = config.headers
|
||||
|
||||
MAX_RETRY = 10
|
||||
|
||||
|
||||
class ReplayChat:
|
||||
@@ -62,7 +61,7 @@ class ReplayChat:
|
||||
チャットデータ取得ループ(_listen)用のスレッド
|
||||
|
||||
_is_alive : bool
|
||||
チャット取得を終了したか
|
||||
チャット取得を停止するためのフラグ
|
||||
'''
|
||||
|
||||
_setup_finished = False
|
||||
@@ -71,7 +70,7 @@ class ReplayChat:
|
||||
def __init__(self, video_id,
|
||||
seektime = 0,
|
||||
processor = DefaultProcessor(),
|
||||
buffer = Buffer(maxsize = 20),
|
||||
buffer = None,
|
||||
interruptable = True,
|
||||
callback = None,
|
||||
done_callback = None,
|
||||
@@ -94,6 +93,7 @@ class ReplayChat:
|
||||
self._pauser.put_nowait(None)
|
||||
|
||||
self._setup()
|
||||
|
||||
if not ReplayChat._setup_finished:
|
||||
ReplayChat._setup_finished = True
|
||||
if interruptable:
|
||||
@@ -154,7 +154,7 @@ class ReplayChat:
|
||||
|
||||
def _listen(self, continuation):
|
||||
''' continuationに紐付いたチャットデータを取得し
|
||||
にチャットデータを格納、
|
||||
BUfferにチャットデータを格納、
|
||||
次のcontinuaitonを取得してループする
|
||||
|
||||
Parameter
|
||||
@@ -193,9 +193,11 @@ class ReplayChat:
|
||||
time.sleep(diff_time)
|
||||
continuation = metadata.get('continuation')
|
||||
except ChatParseException as e:
|
||||
logger.error(f"{str(e)}(動画ID:\"{self.video_id}\")")
|
||||
self.terminate()
|
||||
logger.error(f"{str(e)}(video_id:\"{self.video_id}\")")
|
||||
return
|
||||
except (TypeError , json.JSONDecodeError) :
|
||||
self.terminate()
|
||||
logger.error(f"{traceback.format_exc(limit = -1)}")
|
||||
return
|
||||
|
||||
@@ -224,6 +226,7 @@ class ReplayChat:
|
||||
else:
|
||||
logger.error(f"[{self.video_id}]"
|
||||
f"Exceeded retry count. status_code={status_code}")
|
||||
self.terminate()
|
||||
return None
|
||||
return livechat_json
|
||||
|
||||
@@ -270,7 +273,7 @@ class ReplayChat:
|
||||
'''Listener終了時のコールバック'''
|
||||
try:
|
||||
self.terminate()
|
||||
except CancelledError:
|
||||
except RuntimeError:
|
||||
logger.debug(f'[{self.video_id}]cancelled:{sender}')
|
||||
|
||||
def terminate(self):
|
||||
@@ -281,7 +284,7 @@ class ReplayChat:
|
||||
if self._direct_mode == False:
|
||||
#bufferにダミーオブジェクトを入れてis_alive()を判定させる
|
||||
self._buffer.put({'chatdata':'','timeout':1})
|
||||
logger.info(f'終了しました:[{self.video_id}]')
|
||||
logger.info(f'[{self.video_id}]終了しました')
|
||||
|
||||
@classmethod
|
||||
def shutdown(cls, event, sig = None, handler=None):
|
||||
|
||||
Reference in New Issue
Block a user