diff --git a/src/cli/data.py b/src/cli/data.py index c223a79..c46e726 100644 --- a/src/cli/data.py +++ b/src/cli/data.py @@ -193,7 +193,7 @@ def push_metric(client, competition, metric): def push_pit(client, competition, pit): for variable in pit: - + push_team_pit_data(client, competition, variable, pit[variable]) def check_new_database_matches(client, competition): diff --git a/src/cli/superscript.py b/src/cli/superscript.py index 3dd42cc..70f497f 100644 --- a/src/cli/superscript.py +++ b/src/cli/superscript.py @@ -151,18 +151,16 @@ __all__ = [ # imports: -import asyncio import json import math from multiprocessing import Pool, freeze_support import os import pymongo import sys -import threading import time import traceback import warnings -import websockets +import zmq from interface import splash, log, ERR, INF, stdout, stderr from data import get_previous_time, pull_new_tba_matches, set_current_time, load_match, push_match, load_pit, push_pit, get_database_config, set_database_config, check_new_database_matches @@ -541,43 +539,26 @@ def start(pid_path, verbose = False, profile = False, debug = False): sys.exit(exit_code) else: - + f = open('errorlog.log', 'w+') with daemon.DaemonContext( - working_directory=os.getcwd(), - pidfile=pidfile.TimeoutPIDLockFile(pid_path), - stderr=f + working_directory = os.getcwd(), + pidfile = pidfile.TimeoutPIDLockFile(pid_path), + stderr = f ): - async def handler(client, path): - clients.append(client) - while True: - try: - pong_waiter = await client.ping() - await pong_waiter - time.sleep(3) - except Exception as e: - clients.remove(client) - break + context = zmq.Context() + socket = context.socket(zmq.PUB) + socket.bind("tcp://*:5678") + + socket.send(b'status') - async def send_one(client, data): - await client.send(data) - def send(target, level, message, code = 0): - message_clients = clients.copy() - for client in message_clients: - try: - asyncio.run(send_one(client, message)) - except: - pass - - clients = [] - start_server = websockets.serve(handler, "0.0.0.0", 5678) - - asyncio.get_event_loop().run_until_complete(start_server) - threading.Thread(target = asyncio.get_event_loop().run_forever).start() + socket.send(bytes("status: " + message, 'utf-8')) exit_code = main(send) + socket.close() + f.close() sys.exit(exit_code) def stop(pid_path): diff --git a/src/cli/superscript.spec b/src/cli/superscript.spec index 7664ae0..04cafa7 100644 --- a/src/cli/superscript.spec +++ b/src/cli/superscript.spec @@ -10,8 +10,6 @@ a = Analysis(['superscript.py'], "dnspython", "sklearn.utils._weight_vector", "requests", - "websockets.legacy", - "websockets.legacy.server", ], hookspath=[], runtime_hooks=[], diff --git a/src/requirements.txt b/src/requirements.txt index 644ff65..88cc58b 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -15,5 +15,5 @@ pandas kivy==2.0.0rc2 -websockets +pyzmq python-daemon \ No newline at end of file diff --git a/test/client.py b/test/client.py new file mode 100644 index 0000000..df4c0e4 --- /dev/null +++ b/test/client.py @@ -0,0 +1,14 @@ +import signal +import zmq + +signal.signal(signal.SIGINT, signal.SIG_DFL) + +context = zmq.Context() + +socket = context.socket(zmq.SUB) +socket.connect('tcp://localhost:5678') +socket.setsockopt(zmq.SUBSCRIBE, b'status') + +while True: + message = socket.recv_multipart() + print(f'Received: {message}') \ No newline at end of file