From e6a592bc51c417454c005d32e40c7d4bbfe52c6d Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sun, 9 Jun 2019 21:43:43 +0200 Subject: [PATCH] switch to gunicorn --- Dockerfile | 4 ++-- main.py | 22 ++++++---------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8b4175a..5d1dbb5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,10 +3,10 @@ FROM debian:buster-slim RUN apt-get update && apt-get install -y \ python3-requests \ python3-flask \ - python3-twisted \ + gunicorn3 \ && rm -rf /var/lib/apt/lists/* COPY . /app WORKDIR /app -ENTRYPOINT ["python3", "main.py", "-p", "80"] +ENTRYPOINT ["gunicorn3", "-w1", "-b0.0.0.0:80", "main:app"] EXPOSE 80 diff --git a/main.py b/main.py index bb25710..1fc7bb0 100755 --- a/main.py +++ b/main.py @@ -1222,9 +1222,10 @@ def update_thread() -> None: time.sleep(UPDATE_INTERVAL) -thread = threading.Thread(target=update_thread) -thread.daemon = True -thread.start() +def start_update_thread(): + thread = threading.Thread(target=update_thread) + thread.daemon = True + thread.start() class SrcInfoPackage(object): @@ -1302,15 +1303,11 @@ app = Flask(__name__) app.register_blueprint(packages) app.jinja_env.undefined = StrictUndefined +start_update_thread() def main(argv: List[str]) -> Any: global CACHE_LOCAL - from twisted.internet import reactor - from twisted.web.server import Site - from twisted.web.wsgi import WSGIResource - from twisted.python import log - parser = argparse.ArgumentParser() parser.add_argument("-c", "--cache", action="store_true", help="use local repo cache") @@ -1321,15 +1318,8 @@ def main(argv: List[str]) -> Any: CACHE_LOCAL = args.cache print("http://localhost:%d" % args.port) + app.run(port=args.port, debug=args.debug) - if args.debug: - app.debug = True - log.startLogging(sys.stdout) - - wsgiResource = WSGIResource(reactor, reactor.getThreadPool(), app) - site = Site(wsgiResource) - reactor.listenTCP(args.port, site) - reactor.run() if __name__ == "__main__":