new approach

This commit is contained in:
itsdeka
2021-11-25 12:19:31 +01:00
parent abfafbf8cf
commit faa6075eae
2 changed files with 8 additions and 5 deletions

View File

@@ -7,7 +7,6 @@ import websockets
import socket import socket
import json import json
import time import time
import nest_asyncio
from threading import Thread, Lock from threading import Thread, Lock
from pyee import AsyncIOEventEmitter from pyee import AsyncIOEventEmitter
@@ -15,7 +14,6 @@ from ..utils.custom_logger import CustomLogger
# websocket exceptions # websocket exceptions
from websockets.exceptions import ConnectionClosed, InvalidStatusCode from websockets.exceptions import ConnectionClosed, InvalidStatusCode
nest_asyncio.apply()
class AuthError(Exception): class AuthError(Exception):
""" """
@@ -86,6 +84,8 @@ class GenericWebsocket:
thread and connection. thread and connection.
""" """
self._start_new_socket() self._start_new_socket()
while True:
time.sleep(1)
def get_task_executable(self): def get_task_executable(self):
""" """
@@ -93,10 +93,14 @@ class GenericWebsocket:
""" """
return self._run_socket() return self._run_socket()
def _start_new_async_socket(self):
asyncio.run(self._run_socket())
def _start_new_socket(self, socketId=None): def _start_new_socket(self, socketId=None):
if not socketId: if not socketId:
socketId = len(self.sockets) socketId = len(self.sockets)
asyncio.run(self._run_socket()) worker = Thread(target=self._start_new_async_socket)
worker.start()
return socketId return socketId
def _wait_for_socket(self, socket_id): def _wait_for_socket(self, socket_id):

View File

@@ -5,5 +5,4 @@ pytest-asyncio==0.15.1
six==1.12.0 six==1.12.0
pyee==8.0.1 pyee==8.0.1
aiohttp==3.4.4 aiohttp==3.4.4
isort==4.3.21 isort==4.3.21
nest_asyncio==1.5.1