Does Python(FLASK) have somethink like nodaemon? [duplicate] - python

This question already has answers here:
Auto reloading python Flask app upon code changes
(14 answers)
Closed 1 year ago.
with nodaemon code changes will be displayed without rebooting the server, does Python(FLASK) have somthing like that?

Yes. Nodemon will automatically restart the server everytime you update your code. Flask has a similar feature. To enable it you have to set your environment to development. To do so type the following at the command line:
set flask_env=development
The above works when using a windows cmd line. If you are using bash try:
$ export FLASK_ENV=development
Then start your server.
See: https://flask.palletsprojects.com/en/master/server/

Related

Run Python application on DigitalOcean [duplicate]

This question already has answers here:
Are a WSGI server and HTTP server required to serve a Flask app?
(3 answers)
Closed 9 months ago.
I need help to start my Python application on DigitalOcean droplet. I set up all the settings and now can run my python file. But if I close the Ubuntu console - my loop or any other code (sending requests for example) finish. I want to start a Flask server which will receive webhooks all time when machine works (24/7). How can I start the process without working console on my Desktop? The question is not about Flask, only about endless working program. Thanks.
You could use screen or nohup to have your python script running 24/7.
screen allows you to create a terminal session and detach from it, leaving the process started on it running. You can install it on Ubuntu with the command below. See this tutorial or this one for more information.
sudo apt-get update sudo apt-get install screen
nohup allows you to do the same. It basically runs a command ignoring hangup signals, not stopping when you log out. Unlike screen, nohup is normally already installed by default on Ubuntu. See its manual page for more information about it.
Finally, in case you are interested in knowing more about the differences between screenand nohup, they were explained in this post.

How to run Dash App in background/offline [duplicate]

This question already has answers here:
Are a WSGI server and HTTP server required to serve a Flask app?
(3 answers)
Closed 1 year ago.
I am new to dash app development and created a app which is running in the linux server. It is available to all users in our intranet only when I trigger and online. Once I logoff it is not accessible. How to schedule the app to run continuously even when I am offline. Any responses would be appreciated.
currently it is serving with below command
python app.py
I cant deploy in Heroku due to security restrictions. Docker also unavailable. Any other option would be appreciated.
Regards,
Sudheer
From this description, I guess that you
SSH into the server
Run python app.py
At this point, the app is available
Log off from the SSH connection (e.g. exit command)
At this point, the app is not available any more
If so, this is because the command you run during the SSH session will be terminated when you log off from the session.
There are several ways to keep your app running after you log off. For example,
Run nohub python app.py &.
Run tmux and run python app.py in the tmux window. Then Ctrl+b+d to close the tmux window.
In either way, the app will keep running after you log off from the SSH connection. If my guess about your situation is wrong, please elaborate on your situation more in detail. For example, tell us the series of command you run and what happens with them.
In particular, the term "offline" is not clear in this context. If you are completely offline and not connected even to the intranet, then there is no chance that you can use the app running on the server.

Run script in Django [duplicate]

This question already has answers here:
How to fix 'sudo: no tty present and no askpass program specified' error?
(30 answers)
Closed 6 years ago.
I am trying to run a script in Django. This script needs to be run with sudo and I have setup the sudoers file so that the command can be executed without entering the sudo password. When I am using the default test server, ie >python manage.py runserver 0.0.0.0:8000, the script executes with no problem. However, after deploying Django with Nginx and uWSGI, the command fails and returns the response
sudo: no tty present and no askpass program specified
Is there some sort of configuration that I have missed?
I am using subprocess to execute the script and the code inside the Django view is like this:
subprocess.check_output( "sudo /path/to/file/fileName.sh", shell=True)
You need to add the user you are using to the sudoers list:
Granting the user to use that command without prompting for password should resolve the problem. First open a shell console and type:
sudo visudo
Then edit that file to add to the very end:
username ALL = NOPASSWD: /fullpath/to/command, /fullpath/to/othercommand
eg
john ALL = NOPASSWD: /sbin/poweroff, /sbin/start, /sbin/stop
will allow user 'john' to sudo poweroff, start and stop without being prompted for password.
Look at the bottom of the screen for the keystrokes you need to use in visudo - this is not vi by the way - and exit without saving at the first sign of any problem. Health warning: corrupting this file will have serious consequences, edit with care!
source: How to fix 'sudo: no tty present and no askpass program specified' error?

How do I get a python program to remain active on the server after I close putty? [duplicate]

This question already has answers here:
How to run Node.js as a background process and never die?
(14 answers)
Closed 6 years ago.
I wrote a program a few months ago in python/JavaScript that uses bottle, but when I moved it to my website (hosted on Amazon Web Service), it works when I type: sudo python2.7 moviegame.py, but when I close Putty, the website doesn't show my game.
How do I get the server to keep running my program without relying on my computer?
Typically you would use something like supervisor http://supervisord.org/ or some other process control system. There are many out there.

python: how to run scripts over ssh remotely [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Execute arbitrary python code remotely - can it be done?
I wrote a memory usage check function and it runs fine on one server (say 10.100.110.10).
But I need to run the same script remotely on 10.100.110.11 from 10.100.110.10. I can ssh to 10.100.110.11 from 10.100.110.10. Is there any way to implement that using python built in modules?
I can't use any new modules like Paramico and Unix command
ssh -n user#10.100.110.11 "df -m"
works fine.
If it is not possible, how can I ssh to 10.100.110.11 using a built in Python module?
You cannot remotely run Python code if you're not accessing the Python interpreter on the other side. You could sent the code the the Python's interpreter standard input, but you still have to send the code.
The other solution would be to make your code remote-compatible, and replace all systems calls by their equivalents over SSH (using Paramiko for example).

Categories

Resources