python on heroku. Get SIGHUP error - python

On working through HEROKU's guide to getting Python app to run on HEROKU and one first creates a hello world program ostensibly using python and flask and runs it locally using Foreman. I get an 'unsupported signal SIGHUP' from Ruby/Gems/foreman/engine. I am Running Win7. Anybody else hit this problem or have any ideas ? thanks.

If you are running locally, you can also just run the flask app from the command line using python, skipping Foreman altogether. This is how I run locally on my Windows 7 machines.

This is related to a known issue on Win7: https://github.com/ddollar/foreman/pull/219
Heroku just released a new version of the Foreman gem (v0.48) that resolves this issue. Thanks for your input.

Related

how to make your python web app always running on ubuntu machine

I have a web app that I deployed to a machine that has ubuntu 20 installed
to be able to run the app I should open ssh to the ubuntu machine and then run this command
cd mywebapp
python3 app.py
it works successfully, but once I close the ssh console or reboot the machine or anything happens, it stopped and I have to repeat these commands
I tried to add it as a corn job to be run after machine reboot but it does not work
I post a question in the following link : run python app after server restart does not work using crontab
nothing work with me, and I have to make sure that this web app will always be running because it should be working to send push notification to mobile devices
can anyone please advice, I have been searching and trying for so many time
I'm not expert in it, but two solutions come in my mind:
1- Using systemd:
systemd can be responsible to keep services up.
You can write a custom unit for your app, and config it as a way to be up always.
This tutorial may be useful: writing unit
2- Using Docker:
When you have containerized app, you config it as to come up, on failure or anything like that.
Read about it here
What if you have the calling piece of Python script within a bash script and run that as a daemon:
Your bash script could like below (test.sh):
#!/bin/sh
cd desired/directory
python3 app.py
and you can run the bashscript like this by using nohup:
nohup ./test.sh 0<&- &>/dev/null &
You could refer this, if you want to store the outputs of nohup.

Error with Python subprocess when running Flask app using nginx + WSGI

I have developed a Python web server using Flask, and some of the endpoints make use of the subprocess module to call different executables. On development, using the Flask debug server, everything works fine. However, when running the server along with nginx+WSGI (on the exact same machine), some subprocess calls fail.
For example, one of the tools I'm using is Microsoft's dotnet, which I installed from my user as sudo apt-get install -y aspnetcore-runtime-5.0 and is then called from Python with the subprocess module. When I run the server with python3 server.py, it works like a charm. However, when using nginx and WSGI, the subprocess call fails with an exception that says: /bin/sh: 1: dotnet: not found.
I suspect this is due to the command not being accessible to the user and group running the server. I have used this guide as a reference to deploy the app, and on the wsgi .ini file, I have set uid = javierd and gid = www-data, while on the systemd .service file I have User=javierd, Group=www-data.
I have tried to add the executables' paths to /etc/profile, but it didn't work, and I don't know any other way to fix it. I find also very surprising that this happens to some executables, but not to all, and that it happes to dotnet, for example, which is located at /usr/bin/dotnet and therefore should be accessible to every user. Any idea on how to solve this problem? Furthermore, if somebody could explain me why this is happening, I would really appreciate the effort.
Thanks a lot!
Ok, finally after having a big headache, I noticed the error, and it was really simple.
On the tutorial I linked, when creating the system service file, the following line was included: Environment="PATH=/home/myuser/myfolder/enviroment/bin".
Of course, as this was overriding the path, there was no way of executing the commands. Once I notices it I just removed that line, restarted the service, and it was fixed.

using flask in spyder stuck in local server

I am trying to create a web application using flask. I have already gotten somewhat comfortable with using python, and have done so using spyder, inside of Anacanda Navigator. Now I am playing around with flask doing basic functions and have successful so far by testing it out in local server 127.0.0.1:5000. The problem I am having is that I cannot stop the server once I run the script in spyder. I have stopped the script and run other scripts through the console, but the local server remains the same.
The reason this is a problem for me is because when I try to change files and run a different flask script, the server does not update with the new information. For example, if I run a flask script that returns "Hello World" on the main page, and then I stop that file, open a new file that has a different flask script that returns "The sky is blue" the server does not change when I check it on chrome or any other browser. It will onyl return "Hello World"
I have been able to fix this problem by completely restarting my computer, but I am wondering if there is another way, just to restart the local server, 127.0.0.1:5000. Thank You!
Also I am using windows
I do : "Run > Configuration per file > Execute in an external system terminal",
then when you run your .py containing the app.run, it will be launched in an external console. If you close the console the server will be closed too.
To Kill the local server, you may use Ctrl+C command and not any other command. This command is also mentioned when the server is up and running.
I've been having this precise issue and have been smashing my head against the wall for a couple of hours. I posted the referenced StackOverflow question (my first actually) and it seems that running a script from inside Spyder is the wrong way to go as it leaves runaway background processes running, even after restarting Spyder.
I got the recommendation to only launch my *.py code from the command prompt. Furthermore I was told to do this:
set FLASK_APP=main1.py then set FLASK_DEBUG=1 then flask run
though I'm not sure what that does, so I will investigate. I was about to restart my computer as a last ditch effort until I looked in my Windows Task Manager and found some Python tasks running. After [end task] them both I was able to launch the updated webpage on my local host.

How to edit python file on Google Cloud Shell

I have created the basic "Hello World" web app and deployed it. So I have the URL with my project name included in it. I wanted to create a couple of changes to the source code, but when I try refreshing it shows no changes. How do I make changes?
If you deployed the app
gcloud app update
If it's testing in Cloud Shell
I missed where you stated the app was deployed and wrote the answer below. I'll leave it for future readers or in case it might help.
To stop the local server from the command line, you press the
following:
Mac OS X or Linux: Control-C Windows: Control-Break
Then restart again with
dev_appserver.py app.yaml
This assumes you're completing the App Engine hello world tutorial.
Still not working? Maybe you have multiple processes running or something else is wrong. Let's try killing all of the web server processes and restarting.
ps aux | grep dev_appserver.py
Look at the process number.
kill PROCESS_NUM_HERE
If you see multiple processes after running ps aux... then you should kill all of them.
Then restart
dev_appserver.py app.yaml

pywin32 CreateEvent and Apache

I have a website in Django1.1.1 deployed in Apache2.0. In the backend I have a launcher script that starts three python processes that interact with the frontend. One of these processes uses a Windows Event (using CreateEvent) that communicates with Apache.
My problem is that when I run the launcher script first and then start Apache everything seems to be working fine, but when I start Apache first and then run launcher the process with the Windows event is never launched. On starting the process on command line it dies with the error
pywintypes.error: (5, 'CreateEvent', 'Access is denied.')
I think this is a permission issue where Apache is running as SYSTEM user and the launcher running as me. Any ideas how I can fix this?
It could be something else too, any ideas?
I am a noob on Windows so please bear with me. BTW I am using Windows XP and python 2.4
Thanks
S
UPDATE:
I eventually used python recipe Controlling Windows Services to always launch Apache service post my script. My problem is resolved!
Are you specifying a security descriptor in the call to CreateEvent (through the lpEventAttributes argument)?
See the section 5 (Synchronization Object Security and Access Rights) on the following page for details:
Processes and Threads: Synchronization

Categories