mirror of
https://github.com/titanscouting/tra-superscript.git
synced 2024-11-10 06:54:45 +00:00
Merge pull request #18 from titanscouting/daemon-fix
Fix messaging in daemon
This commit is contained in:
commit
6a4d13a33f
@ -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
|
||||
@ -549,35 +547,18 @@ def start(pid_path, verbose = False, profile = False, debug = False):
|
||||
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")
|
||||
|
||||
async def send_one(client, data):
|
||||
await client.send(data)
|
||||
socket.send(b'status')
|
||||
|
||||
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):
|
||||
|
@ -10,8 +10,6 @@ a = Analysis(['superscript.py'],
|
||||
"dnspython",
|
||||
"sklearn.utils._weight_vector",
|
||||
"requests",
|
||||
"websockets.legacy",
|
||||
"websockets.legacy.server",
|
||||
],
|
||||
hookspath=[],
|
||||
runtime_hooks=[],
|
||||
|
@ -15,5 +15,5 @@ pandas
|
||||
|
||||
kivy==2.0.0rc2
|
||||
|
||||
websockets
|
||||
pyzmq
|
||||
python-daemon
|
14
test/client.py
Normal file
14
test/client.py
Normal file
@ -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}')
|
Loading…
Reference in New Issue
Block a user