Reputation:
I need two http servers in same python application (with two differents ports 8081 and 8082): One for a video stream coming from webcam and sent to WebBrowser; Second one for command (quality, filter, etc.) I don't succeed to define two Flask objects, because 'app.run' is blocking. Is it possible, or do I need to use a Flask and a BaseHTTPServer ? Best regards.
Upvotes: 3
Views: 1659
Reputation:
Ok, Solution is : app.run( threaded=True, ...) Now it is possible to process at same time several requests, for exemple one for video streaming, other for video parameter tuning and so on.
Upvotes: 1
Reputation: 9739
You can call Flask.run(port=8081)
, but not in the same process (as run()
is indeed blocking).
You should create different Flask
instances for each service, and run them in separate commands (although one can be run in background):
run.sh
#!/usr/bin/env sh
# Runs in background:
python app_webcam.py &
# Runs in foreground
python app_command.py
app_webcam.py
# ... (setup you Flask app)
if __name__ == '__main__':
app.run(port=8081)
app_command.py
# ... (setup you Flask app)
if __name__ == '__main__':
app.run(port=8082)
Upvotes: 1