Huge websocket redesign, to support more than a single connection
This commit is contained in:
1 parent
106831cc9a
commit
a45838e088
7 files changed
+370
-236
No files matched your search
@@ -10,10 +10,10 @@ import asyncio
|
||||
import warnings
|
||||
import traceback
|
||||
import threading
|
||||
from typing import Any, Dict, NoReturn
|
||||
from typing import NoReturn
|
||||
|
||||
from twitch import Twitch
|
||||
from constants import SETTINGS_PATH, TERMINATED_STR
|
||||
from constants import JsonType, SETTINGS_PATH, TERMINATED_STR, DEBUG_RAW
|
||||
|
||||
try:
|
||||
import win32api
|
||||
@@ -41,6 +41,8 @@ def terminate() -> NoReturn:
|
||||
raise RuntimeError("Uh oh") # this will never run, solely for MyPy
|
||||
|
||||
|
||||
# extra debug logging level
|
||||
logging.addLevelName(DEBUG_RAW, "DEBUG_RAW")
|
||||
# handle extra stackable '-v' parameter, that switches the logging level
|
||||
logging_level = logging.ERROR
|
||||
if len(sys.argv) > 1:
|
||||
@@ -51,6 +53,9 @@ if len(sys.argv) > 1:
|
||||
logging_level = logging.INFO
|
||||
elif arg in ("-vvv", "-v3"):
|
||||
logging_level = logging.DEBUG
|
||||
elif arg in ("-vvvv", "-v4"):
|
||||
# enables debugging raw messages
|
||||
logging_level = DEBUG_RAW
|
||||
# handle logging stuff
|
||||
root_logger = logging.getLogger()
|
||||
root_logger.addHandler(logging.NullHandler())
|
||||
@@ -62,7 +67,7 @@ logger.setLevel(logging_level)
|
||||
# handle settings
|
||||
try:
|
||||
with open(SETTINGS_PATH, 'r', encoding="utf8") as file:
|
||||
settings: Dict[str, Any] = json.load(file)
|
||||
settings: JsonType = json.load(file)
|
||||
except json.JSONDecodeError as exc:
|
||||
print(f"Error while reading the settings file:\n{str(exc)}")
|
||||
terminate()
|
||||
@@ -99,10 +104,6 @@ except (asyncio.CancelledError, KeyboardInterrupt):
|
||||
# Because we don't want anything from there to actually run during cleanup,
|
||||
# we need to explicitly cancel the task ourselves here.
|
||||
main_task.cancel()
|
||||
# cancel all other tasks
|
||||
for task in asyncio.all_tasks(loop):
|
||||
if not task.done():
|
||||
task.cancel()
|
||||
# main_task was cancelled due to program shutting down - do the cleanup
|
||||
loop.run_until_complete(client.close())
|
||||
# notify we're free to exit
|
||||
|
||||
Reference in new issue
Block a user