Graceful reload of python tornado server [duplicate] - python

This question already has answers here:
Is there a way to deploy new code with Tornado/Python without restarting the server?
(5 answers)
Closed 7 years ago.
I have an HTTP server created by the Tornado framework. I need to update/reload this server without any connection lost and shutdown.
I have no idea how to do it.
Could you get me any clue?

Easy way, do it with nginx.
Start a latest tornado server.
Redirect all new connections to the new tornado server.(Change nginx configure file and reload with nginx -s reload)
Tell the old tornado server shutdown itself if all connections are closed.
Hard way
If you want to change your server on the fly, maybe you could find a way by reading nginx's source code, figure out how nginx -s reload works, but I think you need to do lots of work.

Related

flask won't run outside of localhost [duplicate]

This question already has answers here:
Configure Flask dev server to be visible across the network
(17 answers)
Closed 2 years ago.
I'm sorry this question has been asked before and answered.
The flask app does not serve outside of the local host network.
This is what I've tried before.
ipconfig
What I've Tried
Inbound rule change to allow port 5000.
Changing port to 80 and then to 33 to test
set host to 0.0.0.0
Tried all with app.run(host=) method and cmd line interface
is it something I'm not seeing yet. Please help. Thank you in advance.
You'll need something like ngrok to transfer outside connection to your localhost. Say you are running flask at 8080. Then to access it you'll need ngrok and the command will be ngrok http 8080. This will give another address which can be used to access flask on your localhost. Also, there are many alternates to this method, but ngrok is quick and easy.
Sorry for the vague answer but I cant help much without actually looking at the code. But have you tried running it on an apache server, I did that for a small project in my home and it worked alright.
This is the resource I found useful myself: https://dev.to/willmvs/flask-deployment-on-windows-139b

Quick way to run flask on 0.0.0.0:80 in company's intranet [duplicate]

This question already has answers here:
Configure Flask dev server to be visible across the network
(17 answers)
Closed 3 years ago.
I am noticing that the Flask default server should not be used for the production server.
However, in my case, I just want to share a prototype web application created by Flask in the company's intranet using port80.
I tried to specify port referring to stackoverflow page by the following code.
if __name__ == "__main__":
app.run(host='0.0.0.0',port=80)
But they still run on 127.0.0.1:5000. (refer to screen capture of command prompt)
Does anyone know what I should revise in order to run the flask application using port 80?
Please try to run it with
python <yourfile>.py
flask run might be a cause of your problem
As mentioned in the Documentation, flask run will run the development server on 127.0.0.1:5000 and ignore your app.run:
The run command will start the development server. It replaces the Flask.run() method in most cases.
https://flask.palletsprojects.com/en/1.0.x/cli/#run-the-development-server
So instead of using flask run just execute your script directly with Python.
The correct way to launch this using flask run is by specifying the -h flag:
flask run -h 0.0.0.0

Is it safe to port forward to Flask development server? [duplicate]

This question already has answers here:
Are a WSGI server and HTTP server required to serve a Flask app?
(3 answers)
Is the server bundled with Flask safe to use in production?
(3 answers)
Closed 4 years ago.
I am looking to control my raspberry pi using alexa voice commands and need to open up flask to accept incoming requests from outside my network.
My setup would have alexa using amazons AWS lambda to process the request and send a vocal response back to alexa. An aditional request would be made from the code hosted on AWS to my raspberry pi running flask.
My question is how safe would it be to publicly expose the flask server through port forwarding and what could I do to make this safe or safer?
I have read that changing the debug to False on flask would be advisable. Would it also be possible to set a rule in flask to only accept connections from specific domains?

Run web server locally without exposing it publicly? [duplicate]

This question already has answers here:
How do you configure tomcat to bind to a single ip address (localhost) instead of all addresses?
(3 answers)
Closed 8 years ago.
I am running a dedicated server on Digital Ocean. My site uses Flask on NGINX through Gunicorn. During development I plopped a search engine (solr) on a local VM (through VMWare Fusion) which happens to be running Tomcat. It could have been running any web server per my question. In my app I make all search requests to that local ip: 192.168.1.5. Now, when I install Tomcat on my server and run it you can see it publicly at mysite.com:8080. There's the old welcome screen of Tomcat for the world to see. I want my app to be able to access it locally through localhost:8080 but not show it to the world. Is this possible?
The short answer is no.
While using a hosting plan, so actually anything that you are doing is 'exposed to the world' since you yourself have to access it remotely, like everyone else.
You have two options, the first, configure the Digital Ocean server to only accept connections from your public IP, and the second, keep using your development server locally until you are ready for primetime.

Python psycopg2 + mod_wsgi: connection is very slow and automatically close

I have made a python ladon webservice and I run is on Ubuntu with Apache2 and mod_wsgi. (I use Python 2.6).
The webservice connect to a postgreSQL database with psycopg2 python module.
My problem is that the psycopg2.connection is closed (or destroyed) automatically after a little time (after about 1 or 2 minutes).
The other hand if I run the server with
ladon2.6ctl testserve
command (http://ladonize.org/index.php/Python_Configuration)
than the server is working and the connection is not closed automatically.
I can't understand why the connection is closed with apache+mod_wsgi and in this case the webserver is very slowly.
Can anyone help me?
If you are using mod_wsgi in embedded moe, especially with preform MPM for Apache, then likely that Apache is killing off the idle processes. Try using mod_wsgi daemon mode, which keeps process persistent and see if it makes a difference.

Categories