import logging import threading import json from flask import Flask, jsonify, request from waitress import serve HOST_ADDRESS = "192.168.1.191" PORT_ADDRESS = 5000 app = Flask(__name__) @app.route("/conjurer", methods=["POST"]) def answer_external_command(): record = json.loads(request.data) app.logger.info(record) #if "UUID" in record and "QUERY" in record and "AUTHOR" in record: # answer_data = "Query logged" #return_data = ( # jsonify(isError=False, message="Success", statusCode=200, data=answer_data), # 200, #) #return return_data return jsonify("SUCCESS") @app.route("/conjurer", methods=["GET"]) def check_alive(): return jsonify("ALIVE") def flask_debug(_logger): """ The `flask_debug` function starts a Flask application in debug mode without using the reloader. Do not use for production for fucks sake. """ _logger.info("Attempt debug") # trunk-ignore(bandit/B201) app.run(debug=True, use_reloader=False, host=HOST_ADDRESS, port=PORT_ADDRESS) def waitress_run(_logger): """ The `waitress_run` function serves the `app` on host "0.0.0.0" and port 5000 using the Waitress WSGI server. """ _logger.info("Attempt waitress") serve(app, host=HOST_ADDRESS, port=PORT_ADDRESS) def scan_queue(comm_q,out_queue): while True: data = comm_q.get() print(data) out_queue.put("Test") def comm_subroutine(in_comm_q, out_com_q): in_queue = in_comm_q out_queue = out_com_q logger = logging.getLogger('conjurer_musician') logger.setLevel(logging.DEBUG) logger.info("Started") threads = [] threads.append(threading.Thread(target=waitress_run, args=(logger,))) threads.append(threading.Thread(target=scan_queue, args=(in_queue,out_queue))) for worker in threads: worker.start() for worker in threads: worker.join()