I was playing with bottle on heroku and wanted to switch for a more "production" WSGI server gunicorn. Here's my setup:
import os
import bottle
from bottle import route, run, template, request, static_file, error
class StripPathMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, e, h):
e['PATH_INFO'] = e['PATH_INFO'].rstrip('/')
return self.app(e, h)
# ................................................................. #
@error(404)
def error404(error):
return template('view/404.tpl')
app = bottle.app()
run(app=StripPathMiddleware(app), server='gunicorn', host='0.0.0.0', port=int(os.environ.get("PORT", 5000)), debug=True, workers=3)
And here's my Procfile:
web: gunicorn SimpleServer:app -w 3
I tried Procfile with and without setting number of workers and so in the SimpleServer.py application.
On a local machine it only works if in app I have workers=3 and I'm not specifying workers starting gunicorn:
(bottleServ)caerus@Artem:~/bottleServ$ gunicorn SimpleServer:app
2013-02-02 23:23:48 [18133] [INFO] Starting gunicorn 0.17.2
2013-02-02 23:23:48 [18133] [INFO] Listening at: http://127.0.0.1:8000 (18133)
2013-02-02 23:23:48 [18133] [INFO] Using worker: sync
2013-02-02 23:23:48 [18138] [INFO] Booting worker with pid: 18138
Bottle v0.11.6 server starting up (using GunicornServer(workers=3))...
Listening on http://0.0.0.0:5000/
Hit Ctrl-C to quit.
2013-02-02 23:23:48 [18138] [INFO] Starting gunicorn 0.17.2
2013-02-02 23:23:48 [18138] [INFO] Listening at: http://0.0.0.0:5000 (18138)
2013-02-02 23:23:48 [18138] [INFO] Using worker: sync
2013-02-02 23:23:48 [18139] [INFO] Booting worker with pid: 18139
2013-02-02 23:23:48 [18140] [INFO] Booting worker with pid: 18140
2013-02-02 23:23:48 [18141] [INFO] Booting worker with pid: 18141
But there's a problem with foreman start, doesn't matter what settings I use I get:
(bottleServ)caerus@Artem:~/bottleServ$ foreman start
23:31:57 web.1 | started with pid 18192
23:31:58 web.1 | 2013-02-02 23:31:58 [18195] [INFO] Starting gunicorn 0.17.2
23:31:58 web.1 | 2013-02-02 23:31:58 [18195] [INFO] Listening at: http://0.0.0.0:5000 (18195)
23:31:58 web.1 | 2013-02-02 23:31:58 [18195] [INFO] Using worker: sync
23:31:58 web.1 | 2013-02-02 23:31:58 [18200] [INFO] Booting worker with pid: 18200
23:31:58 web.1 | 2013-02-02 23:31:58 [18201] [INFO] Booting worker with pid: 18201
23:31:58 web.1 | 2013-02-02 23:31:58 [18202] [INFO] Booting worker with pid: 18202
23:31:58 web.1 | Bottle v0.11.6 server starting up (using GunicornServer(workers=3))...
23:31:58 web.1 | Listening on http://0.0.0.0:5000/
23:31:58 web.1 | Hit Ctrl-C to quit.
23:31:58 web.1 | 2013-02-02 23:31:58 [18202] [INFO] Starting gunicorn 0.17.2
23:31:58 web.1 | 2013-02-02 23:31:58 [18202] [ERROR] Connection in use: ('0.0.0.0', 5000)
23:31:58 web.1 | 2013-02-02 23:31:58 [18202] [ERROR] Retrying in 1 second.
23:31:58 web.1 | Bottle v0.11.6 server starting up (using GunicornServer(workers=3))...
23:31:58 web.1 | Bottle v0.11.6 server starting up (using GunicornServer(workers=3))...
23:31:58 web.1 | Listening on http://0.0.0.0:5000/
23:31:58 web.1 | Listening on http://0.0.0.0:5000/
23:31:58 web.1 | Hit Ctrl-C to quit.
23:31:58 web.1 | Hit Ctrl-C to quit.
23:31:58 web.1 | 2013-02-02 23:31:58 [18200] [INFO] Starting gunicorn 0.17.2
23:31:58 web.1 | 2013-02-02 23:31:58 [18201] [INFO] Starting gunicorn 0.17.2
23:31:58 web.1 | 2013-02-02 23:31:58 [18200] [ERROR] Connection in use: ('0.0.0.0', 5000)
23:31:58 web.1 | 2013-02-02 23:31:58 [18201] [ERROR] Connection in use: ('0.0.0.0', 5000)
23:31:58 web.1 | 2013-02-02 23:31:58 [18200] [ERROR] Retrying in 1 second.
23:31:58 web.1 | 2013-02-02 23:31:58 [18201] [ERROR] Retrying in 1 second.
Any ideas would be appreciated! )
You are starting gunicorn to run the app, and then using Bottle's 'run' to spawn another server (on Heroku, at least). The reason you get the errors is that the initial server takes port 5000 and the second server can't access it. Try just running your bottle app (python SimpleServer.py) it should create the server itself. Also, when you pass 'app' into run, the http server spawns another copy of your app (which spawns another gunicorn server), so just remove that.
run(server='gunicorn', host='0.0.0.0', port=int(os.environ.get("PORT", 5000)), debug=True, workers=X)
python SimpleServer.py
Should be all you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With