Disable _pauser when callback is unset
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from . import mylogger
|
from . import mylogger
|
||||||
|
|
||||||
LOGGER_MODE = None
|
LOGGER_MODE = logging.DEBUG
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36'}
|
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36'}
|
||||||
|
|||||||
@@ -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.live import Parser
|
from ..parser.live import Parser
|
||||||
from .. import config
|
from .. import config
|
||||||
@@ -148,11 +148,13 @@ class LiveChatAsync:
|
|||||||
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= liveparam.getparam(self.video_id)
|
||||||
livechat_json = (await
|
livechat_json = (await
|
||||||
self._get_livechat_json(continuation, session, headers)
|
self._get_livechat_json(continuation, session, headers)
|
||||||
)
|
)
|
||||||
@@ -239,14 +241,17 @@ class LiveChatAsync:
|
|||||||
"既に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
|
||||||
|
|
||||||
@@ -270,12 +275,10 @@ class LiveChatAsync:
|
|||||||
@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()
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ def _times(past_sec):
|
|||||||
return list(map(lambda x:int(x*1000000),[_ts1,_ts2,_ts3,_ts4,_ts5]))
|
return list(map(lambda x:int(x*1000000),[_ts1,_ts2,_ts3,_ts4,_ts5]))
|
||||||
|
|
||||||
|
|
||||||
def getparam(video_id,past_sec = 60):
|
def getparam(video_id,past_sec = 0):
|
||||||
'''
|
'''
|
||||||
Parameter
|
Parameter
|
||||||
---------
|
---------
|
||||||
|
|||||||
Reference in New Issue
Block a user