Comments (4)
Complete code reproducing the context, which would hopefully also become a skeleton (or inspiration) for a flaks test, after an api transparency into failure to use the specified server port has been very hopefully incorporated in flask:
from flask import Flask
from werkzeug.serving import run_simple
from multiprocessing import Process
app = Flask(__name__)
def start():
print('starting a flask server')
try:
started = run_simple('127.0.0.1', 5000, app)
except Exception as e:
print(f'the flask web server crashed with an exception:\n{e}\n')
else:
# of course we will never get here unless the server shut down without throwing
print(f'the flask web server finished with return value {started}')
if __name__ == '__main__':
flask_process = Process(target=start, daemon=True)
flask_process.start()
start()
Note that, the messages about the port being unavailable come out on stderr, same as success messages such as the following type, and hence this leaves no deterministic way for the code starting the server to resolve the status of the server, other than parsing stderr:
127.0.0.1 - - [28/Apr/2024 13:31:24] "GET / HTTP/1.1" 200 -
from flask.
Not sure what you are trying to do, but keep in mind that this server is ONLY meant for development purposes, NOT for anything else. So if you want to run a flask app embedded in some other application for whatever reason, using run_simple
is not what you should do.
from flask.
Makes sense. My scenario is borderline in that regard. Will I have that kind of api-laden way of knowing the status of the server when using a non Werkzeug WSGI component?
from flask.
Okay, I understand then that no underlying supported WSGI server component can be controlled (start and stop) robustly from Flask code then, and that that is not planned either.
from flask.
Related Issues (20)
- transfer-encoding: debug server behavior differs from test client HOT 1
- Keep code running after response has been sent. (To respond with HTTP requests to other servers) HOT 6
- Secret Key Rotation HOT 1
- @app.errorhandler() cannot be used in blueprint when debug=False
- Flask is not running when Debug is True on Windows HOT 1
- Starter example results in 404 error HOT 4
- How to avoid duplicate threads in debug mode
- Unable to silence logging messages HOT 1
- Broken HTML Markup in Template Inheritance HOT 1
- When using Flask to receive multiple files, an extra ā0Dā appears at the end of some images HOT 1
- Use of `hashlib.sha1` causes issue in FIPS build HOT 3
- Post request response time spikes HOT 1
- HTTP response status 204 (`No Content`) includes superfluous `Content-Type` header HOT 1
- Unable to start flask3.0 app on a minimal implementation with `invalid syntax. Perhaps you forgot a comma? (scaffold.py, line 295)` HOT 2
- Calling `flash` after `get_flashed_messages` fails HOT 3
- Conflicting cookies shenanigans with `SESSION_COOKIE_DOMAIN` HOT 7
- Add support for partitioned session cookies
- Change of query string encoding behaviour in flask 3.0 HOT 1
- send_from_directory unclosed file error HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask.