nprapps/dailygraphics

fab app sometimes returns a fatal error, but appears to run invisibly in the background

alykat opened this issue · 1 comments

Sometimes when I run fab app, I get this error message and the webserver appears to stop:

(dailygraphics)ahurt-npr:dailygraphics AHurt$ fab app
[localhost] local: gunicorn -b 0.0.0.0:8000 --debug --reload app:wsgi_app

Fatal error: local() encountered an error (return code 1) while executing 'gunicorn -b 0.0.0.0:8000 --debug --reload app:wsgi_app'

Aborting.
(dailygraphics)ahurt-npr:dailygraphics AHurt$

But if I pull up http://localhost:8000, pages are still loading.

Restarting my computer seems to fix the problem, at least initially. But it recurs with some regularity.

I've seen this happen on at least one other person's machine.

After consulting with @TylerFisher @eads @dannydb:

This error happens when you don't explicitly quit out of a gunicorn session (say, if you close your terminal window without first hitting ctrl+c to stop the webserver).

One way to fix it: Add a function to your .bash_profile...

nano ~/.bash_profile

Add this to the bottom:

# Sometimes yosemite crashes with a gunicorn server up
# and when it comes back up there is a python process blocking port 8000
# kill that process with this function
# http://stackoverflow.com/questions/3855127/find-and-kill-process-locking-port-3000-on-mac
function killport() {
    lsof -i TCP:$1 | grep LISTEN | awk '{print $2}' | xargs kill -9
}

Save, and then refresh your terminal window:

source ~/.bash_profile

Once you've set that up, you can type this command to kill the port in question (usually 8000) any time you see this error:

killport 8000
fab app