2025-02-05 13:20:09 +11:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import platform
|
2023-12-28 13:34:48 +11:00
|
|
|
from main import app
|
2025-02-05 13:20:09 +11:00
|
|
|
from waitress import serve
|
2023-12-28 13:34:48 +11:00
|
|
|
|
|
|
|
|
2025-02-05 13:51:01 +11:00
|
|
|
threads = 4
|
2025-02-05 13:20:09 +11:00
|
|
|
|
|
|
|
def gunicornServer():
|
2025-02-05 13:51:01 +11:00
|
|
|
from gunicorn.app.base import BaseApplication
|
|
|
|
class GunicornApp(BaseApplication):
|
|
|
|
def __init__(self, app, options=None):
|
|
|
|
self.options = options or {}
|
|
|
|
self.application = app
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
def load_config(self):
|
|
|
|
for key, value in self.options.items():
|
|
|
|
if key in self.cfg.settings and value is not None:
|
|
|
|
self.cfg.set(key.lower(), value)
|
|
|
|
|
|
|
|
def load(self):
|
|
|
|
return self.application
|
2023-12-28 13:34:48 +11:00
|
|
|
options = {
|
|
|
|
'bind': '0.0.0.0:5000',
|
2025-02-05 13:20:09 +11:00
|
|
|
'workers': 2,
|
2023-12-28 13:34:48 +11:00
|
|
|
'threads': threads,
|
|
|
|
}
|
|
|
|
gunicorn_app = GunicornApp(app, options)
|
2025-02-05 13:20:09 +11:00
|
|
|
print(f'Starting server with Gunicorn on {platform.system()} with {threads} threads...', flush=True)
|
2023-12-28 13:34:48 +11:00
|
|
|
gunicorn_app.run()
|
2025-02-05 13:20:09 +11:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# Check if --gunicorn is in the command line arguments
|
|
|
|
if "--gunicorn" in sys.argv:
|
|
|
|
gunicornServer()
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
print(f'Starting server with Waitress on {platform.system()} with {threads} threads...', flush=True)
|
|
|
|
print(f'Press Ctrl+C to stop the server', flush=True)
|
|
|
|
print(f'Serving on http://0.0.0.0:5000/', flush=True)
|
|
|
|
serve(app, host="0.0.0.0", port=5000, threads=threads)
|