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
Former-commit-id: 6a4d13a33f
This commit is contained in:
commit
49ee02d6fa
@ -151,18 +151,16 @@ __all__ = [
|
|||||||
|
|
||||||
# imports:
|
# imports:
|
||||||
|
|
||||||
import asyncio
|
|
||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
from multiprocessing import Pool, freeze_support
|
from multiprocessing import Pool, freeze_support
|
||||||
import os
|
import os
|
||||||
import pymongo
|
import pymongo
|
||||||
import sys
|
import sys
|
||||||
import threading
|
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
import warnings
|
import warnings
|
||||||
import websockets
|
import zmq
|
||||||
|
|
||||||
from interface import splash, log, ERR, INF, stdout, stderr
|
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
|
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
|
stderr = f
|
||||||
):
|
):
|
||||||
|
|
||||||
async def handler(client, path):
|
context = zmq.Context()
|
||||||
clients.append(client)
|
socket = context.socket(zmq.PUB)
|
||||||
while True:
|
socket.bind("tcp://*:5678")
|
||||||
try:
|
|
||||||
pong_waiter = await client.ping()
|
|
||||||
await pong_waiter
|
|
||||||
time.sleep(3)
|
|
||||||
except Exception as e:
|
|
||||||
clients.remove(client)
|
|
||||||
break
|
|
||||||
|
|
||||||
async def send_one(client, data):
|
socket.send(b'status')
|
||||||
await client.send(data)
|
|
||||||
|
|
||||||
def send(target, level, message, code = 0):
|
def send(target, level, message, code = 0):
|
||||||
message_clients = clients.copy()
|
socket.send(bytes("status: " + message, 'utf-8'))
|
||||||
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()
|
|
||||||
|
|
||||||
exit_code = main(send)
|
exit_code = main(send)
|
||||||
|
socket.close()
|
||||||
|
f.close()
|
||||||
sys.exit(exit_code)
|
sys.exit(exit_code)
|
||||||
|
|
||||||
def stop(pid_path):
|
def stop(pid_path):
|
||||||
|
@ -10,8 +10,6 @@ a = Analysis(['superscript.py'],
|
|||||||
"dnspython",
|
"dnspython",
|
||||||
"sklearn.utils._weight_vector",
|
"sklearn.utils._weight_vector",
|
||||||
"requests",
|
"requests",
|
||||||
"websockets.legacy",
|
|
||||||
"websockets.legacy.server",
|
|
||||||
],
|
],
|
||||||
hookspath=[],
|
hookspath=[],
|
||||||
runtime_hooks=[],
|
runtime_hooks=[],
|
||||||
|
@ -15,5 +15,5 @@ pandas
|
|||||||
|
|
||||||
kivy==2.0.0rc2
|
kivy==2.0.0rc2
|
||||||
|
|
||||||
websockets
|
pyzmq
|
||||||
python-daemon
|
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