Fix getting arcparam when resume

This commit is contained in:
taizan-hokuto
2020-01-02 15:12:48 +09:00
parent 2bb481a228
commit d6ea673f98
2 changed files with 13 additions and 10 deletions

View File

@@ -154,7 +154,7 @@ class LiveChatAsync:
prohibit from blocking by putting None into _pauser. prohibit from blocking by putting None into _pauser.
''' '''
self._pauser.put_nowait(None) self._pauser.put_nowait(None)
continuation= liveparam.getparam(self.video_id) continuation= liveparam.getparam(self.video_id,3)
livechat_json = (await livechat_json = (await
self._get_livechat_json(continuation, session, headers) self._get_livechat_json(continuation, session, headers)
) )
@@ -185,6 +185,7 @@ class LiveChatAsync:
return return
logger.debug(f"[{self.video_id}]チャット取得を終了しました。") logger.debug(f"[{self.video_id}]チャット取得を終了しました。")
self.terminate()
async def _get_livechat_json(self, continuation, session, headers): async def _get_livechat_json(self, continuation, session, headers):
''' '''
@@ -209,7 +210,6 @@ class LiveChatAsync:
else: else:
logger.error(f"[{self.video_id}]" logger.error(f"[{self.video_id}]"
f"Exceeded retry count. status_code={status_code}") f"Exceeded retry count. status_code={status_code}")
self.terminate()
return None return None
return livechat_json return livechat_json

View File

@@ -8,7 +8,7 @@ import traceback
import urllib.parse import urllib.parse
from aiohttp.client_exceptions import ClientConnectorError from aiohttp.client_exceptions import ClientConnectorError
from concurrent.futures import CancelledError from concurrent.futures import CancelledError
from queue import Queue from asyncio import Queue
from .buffer import Buffer from .buffer import Buffer
from ..parser.replay import Parser from ..parser.replay import Parser
from .. import config from .. import config
@@ -153,11 +153,13 @@ class ReplayChatAsync:
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
while(continuation and self._is_alive): while(continuation and self._is_alive):
if self._pauser.empty(): if self._pauser.empty():
#pause '''pause'''
await self._pauser.get() await self._pauser.get()
#resume '''resume:
#prohibit from blocking by putting None into _pauser. prohibit from blocking by putting None into _pauser.
'''
self._pauser.put_nowait(None) self._pauser.put_nowait(None)
#continuation= arcparam.get(self.video_id)
livechat_json = (await livechat_json = (await
self._get_livechat_json(continuation, session, headers) self._get_livechat_json(continuation, session, headers)
) )
@@ -244,14 +246,17 @@ class ReplayChatAsync:
"既にcallbackを登録済みのため、get()は実行できません。") "既にcallbackを登録済みのため、get()は実行できません。")
def pause(self): def pause(self):
if self._callback is None:
return
if not self._pauser.empty(): if not self._pauser.empty():
self._pauser.get() self._pauser.get_nowait()
def resume(self): def resume(self):
if self._callback is None:
return
if self._pauser.empty(): if self._pauser.empty():
self._pauser.put_nowait(None) self._pauser.put_nowait(None)
def is_alive(self): def is_alive(self):
return self._is_alive return self._is_alive
@@ -275,12 +280,10 @@ class ReplayChatAsync:
@classmethod @classmethod
def _set_exception_handler(cls, handler): def _set_exception_handler(cls, handler):
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
#default handler: cls._handle_exception
loop.set_exception_handler(handler) loop.set_exception_handler(handler)
@classmethod @classmethod
def _handle_exception(cls, loop, context): def _handle_exception(cls, loop, context):
#msg = context.get("exception", context["message"])
if not isinstance(context["exception"],CancelledError): if not isinstance(context["exception"],CancelledError):
logger.error(f"Caught exception: {context}") logger.error(f"Caught exception: {context}")
loop= asyncio.get_event_loop() loop= asyncio.get_event_loop()