Skip to content

Commit 362d0f3

Browse files
committed
[tasks] Added uWSGI integration into invoke app.run command
1 parent 9e32444 commit 362d0f3

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

tasks/app/run.py

+26-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ def run(
2525
port=5000,
2626
flask_config=None,
2727
install_dependencies=True,
28-
upgrade_db=True
28+
upgrade_db=True,
29+
uwsgi=False,
30+
uwsgi_mode='http',
31+
uwsgi_extra_options='',
2932
):
3033
"""
3134
Run Example RESTful API Server.
@@ -56,11 +59,25 @@ def run(
5659
)
5760

5861
use_reloader = app.debug
59-
if platform.system() == 'Windows':
60-
warnings.warn(
61-
"Auto-reloader feature doesn't work on Windows. "
62-
"Follow the issue for more details: "
63-
"https://github.com/frol/flask-restplus-server-example/issues/16"
64-
)
65-
use_reloader = False
66-
app.run(host=host, port=port, use_reloader=use_reloader)
62+
if uwsgi:
63+
uwsgi_args = [
64+
"uwsgi",
65+
"--need-app",
66+
"--manage-script-name",
67+
"--mount", "/=app:create_app()",
68+
"--%s-socket" % uwsgi_mode, "%s:%d" % (host, port),
69+
]
70+
if use_reloader:
71+
uwsgi_args += ["--python-auto-reload", "2"]
72+
if uwsgi_extra_options:
73+
uwsgi_args += uwsgi_extra_options.split(' ')
74+
os.execvpe('uwsgi', uwsgi_args, os.environ)
75+
else:
76+
if platform.system() == 'Windows':
77+
warnings.warn(
78+
"Auto-reloader feature doesn't work on Windows. "
79+
"Follow the issue for more details: "
80+
"https://github.com/frol/flask-restplus-server-example/issues/16"
81+
)
82+
use_reloader = False
83+
return app.run(host=host, port=port, use_reloader=use_reloader)

0 commit comments

Comments
 (0)