I build my flask app, it requires external files through the runtime.
when I build the app, meaning I run > gunicorn app:app (the app startup file is called app.py but that didn't bother). It runs awesomely.
Now when I decided to make a sort of shell script to execute it (actually to make a couple of dependencies and environment checking but for the sake of simplifying, I created startup.sh in the same directory as app.py and it contains only the following instruction unquoted: "gunicorn app:app"), it just throws errors.
and this is the last one ...
Please help..
yep just as I guessed, it should be run within the script inside a virtualenv so that it will execute python 3 :)
Related
I was wondering how I could run some external python scripts on my django application while it is running with gunicorn and nginx ?
Locally without gunicorn and web server, I would just open a python shell using the below:
python manage.py shell
Then run my python script on my django application with the following:
exec(open('myscript.py').read())
Can you please advise ?
PS: I need to run the script on specific time and not on the startup.
Kind regards.
You can just import the script into one of your Django project files like settings.py and then it will just run at the same time.
I've deployed my app on Heroku and run dyno. By default it searches for main.py module and runs it, but I want to specify the folder and app to run. How can I do this?
This is how it's normally works by default
But I want to run app from the "app" folder as it illustrated in the picture
in Procfile we can include our processes and name them as it show in code below
proc_name: python folder_name/app_name.py
And run it on Heroku CLI
heroku ps:scale proc_name=1
I recently created a web app and used the suggested file structuring from flask for separating views in different files. see here, http://flask.pocoo.org/docs/0.12/patterns/packages/.
But I also need to have the threaded parameter set to true which I would usually do at app.run(threaded=True) stage of testing. But I now run the app a different way, i tried putting "threaded=True" into my setup.py and that didn't do anything and was wondering how to get this working.
Just tell the flask run command to use threads:
$ export FLASK_APP=yourapplication
$ flask run --with-threads
Don't put this decision in your code; it is up to your WSGI server to run with threads or not.
You can see what options flask run accepts with flask run --help.
I'm trying to run a simple hello world python program on my heroku server. I'm new to heroku.I was able to successfully deploy my script to heroku.
My python script and procfile are given below,
hi.py
print("hello world")
Procfile
web: python hi.py
I got "Hello world" as output when i ran heroku run web on my terminal.But when i try to run the app using heroku web url it shows the following error.
Application Error An error occurred in the application and your page
could not be served. Please try again in a few moments.
What did i do wrong here? I'm newbie to heroku & its concepts, please do bare.
There are three types of dyno configurations available on Heroku:
Web -- receives web traffic.
Worker -- keeps processing tasks/queues in the background.
One-off -- executed once. e.g.: backup.
If you're interested in running a script, do not care about receiving web traffic on it, and don't have a queue to process, then One-off dynos are likely what you'll want to use. This would be useful for database migrations or backups and whatnot.
Minimal example below.
Sample one-off dyno with Heroku and python AKA “hello world”
This assumes you have already created your app on Heroku and are able to use Herolu CLI from the command-line.
A minimal “hello world” Python script would then look like this. Only 2 files required:
requirements.txt Required, but can be left empty.
task.py with content print("hello world")
Then deploy to Heroku, e.g.:
git add .;
git commit -m "My first commit";
git push heroku master
After that, you'll be able to run your script with heroku run python task.py (and should see the long-awaited hello world in the output.)
If you want to run your program at specific times, use the free Heroku Scheduler add-on.
FYI, Procfile is optional. If you set it to hello: python task.py then you'll be able to run your program with just heroku run hello.
(Note that leaving requirements.txt empty will trigger You must give at least one requirement to install (see "pip help install") warnings on deploy. It's just a warning though and doesn't prevent proper deployment of the program.)
I disagree and state you want flask
main_app.py
import flask
app = flask.Flask(__name__)
#app.route("/")
def index():
#do whatevr here...
return "Hello Heruko"
then change your procfile to web: gunicorn main_app:app --log-file -
I am having issues deploying my Pyramid app on Heroku. It runs fine locally but as soon as I try to launch it I receive this error "pkg_resources.DistributionNotFound: mymedaproject". mymedaproject is the name of my project and is not a python library which is why I am confused. I followed the instructions from this recipe to get to this point:
http://pyramid-cookbook.readthedocs.org/en/latest/deployment/heroku.html
Any ideas?
May be you forgot to put your python project mymedaproject in development mode. What follows is the relevant part of the cookbook recipe.
Create a Procfile
$ echo "web: ./run" > Procfile
Create run with the following:
#!/bin/bash
python setup.py develop
python runapp.py
The first line puts your python project in development mode and enables Paste to load it using your INI file. Make sure Procfile, run, runapp.py and setup.py are in same directory.
References
Getting Started with Python on Heroku
Process Types and the Procfile
Optimization
running a script using a Procfile should work without making it executable
$ echo "web: sh ./run" > Procfile
Check your .gitignore file that it isn't blocking any egg or egg-info information.
If it is, Heroku won't be receiving the egg for your application.