Git Product home page Git Product logo

Comments (4)

matanox avatar matanox commented on May 22, 2024

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.

ThiefMaster avatar ThiefMaster commented on May 22, 2024

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.

matanox avatar matanox commented on May 22, 2024

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.

matanox avatar matanox commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.