I am trying to use a websocket (https://websockets.readthedocs.io/en/stable/) using multithreading. What I want is to keep getting data while my program continues running, however, when I'm doing it like the code below, the server isn't receiving any connections from a client. I was running it before on the main thread and it was working well.
async def hello(websocket, path):
while True:
data = await websocket.recv()
print(data)
await websocket.send(data)
def between_callback():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
ws_server = websockets.serve(hello, '192.168.0.115', 8899)
loop.run_until_complete(ws_server)
loop.close()
if __name__ == "__main__":
_thread = threading.Thread(target=between_callback)
_thread.start()
# Do something in main thread