format
This commit is contained in:
parent
42ae40c0cd
commit
d362a6c922
|
@ -64,7 +64,7 @@ class SocketWrapper:
|
|||
LOG.debug("Connecting to {}:{}".format(self.host, self.port))
|
||||
self.soc = _try_with_backoff(
|
||||
lambda: socket.create_connection((self.host, self.port)),
|
||||
lambda e: e is OSError and e.errno == 111
|
||||
lambda e: e is OSError and e.errno == 111,
|
||||
)
|
||||
LOG.info("Socket Connected")
|
||||
|
||||
|
@ -72,7 +72,7 @@ class SocketWrapper:
|
|||
LOG.info("Server Binding to {}:{}".format(self.host, self.port))
|
||||
self.soc = _try_with_backoff(
|
||||
lambda: socket_create_server((self.host, self.port)),
|
||||
lambda e: e is OSError and e.errno == 98
|
||||
lambda e: e is OSError and e.errno == 98,
|
||||
)
|
||||
LOG.info("Server Bound")
|
||||
|
||||
|
@ -161,12 +161,13 @@ class MessageQueue:
|
|||
self.closed = False
|
||||
self.process_worker = threading.Thread(
|
||||
target=(
|
||||
process_messages_client if side == Side.CLIENT
|
||||
process_messages_client
|
||||
if side == Side.CLIENT
|
||||
else process_messages_server
|
||||
),
|
||||
args=(SocketWrapper(host, port), self),
|
||||
daemon=True,
|
||||
name="MessageQueue/" + str(side)
|
||||
name="MessageQueue/" + str(side),
|
||||
)
|
||||
self.process_worker.start()
|
||||
|
||||
|
|
|
@ -7,21 +7,16 @@ import message_queue
|
|||
|
||||
|
||||
class MessageQueueTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
def test_message_queue(self):
|
||||
port = random.randint(10000, 65535)
|
||||
server_queue = message_queue.MessageQueue(
|
||||
host="localhost",
|
||||
port=port,
|
||||
side=message_queue.Side.SERVER
|
||||
host="localhost", port=port, side=message_queue.Side.SERVER
|
||||
)
|
||||
client_queue = message_queue.MessageQueue(
|
||||
host="localhost",
|
||||
port=port,
|
||||
side=message_queue.Side.CLIENT
|
||||
host="localhost", port=port, side=message_queue.Side.CLIENT
|
||||
)
|
||||
# Worker threads + main thread
|
||||
self.assertEqual(threading.active_count(), 3)
|
||||
|
|
|
@ -222,14 +222,10 @@ def main():
|
|||
side=message_queue.Side.SERVER,
|
||||
)
|
||||
flask_thread = threading.Thread(
|
||||
target=app.run,
|
||||
kwargs={"port": args.matrix_api_port},
|
||||
daemon=True,
|
||||
target=app.run, kwargs={"port": args.matrix_api_port}, daemon=True,
|
||||
)
|
||||
receive_worker = threading.Thread(
|
||||
target=receive_messages,
|
||||
args=(appservice, queue),
|
||||
daemon=True,
|
||||
target=receive_messages, args=(appservice, queue), daemon=True,
|
||||
)
|
||||
flask_thread.start()
|
||||
receive_worker.start()
|
||||
|
|
22
wrapper.py
22
wrapper.py
|
@ -42,15 +42,13 @@ def send_process_output(
|
|||
LOG.info(line.rstrip("\n"))
|
||||
result = prog.search(line)
|
||||
if result:
|
||||
LOG.info("user: {} msg: {}".format(
|
||||
result.group(3),
|
||||
result.group(4).rstrip("\n"),
|
||||
))
|
||||
LOG.info(
|
||||
"user: {} msg: {}".format(
|
||||
result.group(3), result.group(4).rstrip("\n"),
|
||||
)
|
||||
)
|
||||
msg_queue.add(
|
||||
{
|
||||
"user": result.group(3),
|
||||
"msg": result.group(4).rstrip("\n"),
|
||||
},
|
||||
{"user": result.group(3), "msg": result.group(4).rstrip("\n"),},
|
||||
)
|
||||
|
||||
|
||||
|
@ -80,14 +78,10 @@ def main():
|
|||
side=message_queue.Side.CLIENT,
|
||||
)
|
||||
send_worker = threading.Thread(
|
||||
target=send_process_output,
|
||||
args=(wrapper, queue),
|
||||
daemon=True,
|
||||
target=send_process_output, args=(wrapper, queue), daemon=True,
|
||||
)
|
||||
receive_worker = threading.Thread(
|
||||
target=relay_queue_input,
|
||||
args=(wrapper, queue),
|
||||
daemon=True,
|
||||
target=relay_queue_input, args=(wrapper, queue), daemon=True,
|
||||
)
|
||||
send_worker.start()
|
||||
receive_worker.start()
|
||||
|
|
Loading…
Reference in New Issue