2

私はherokuでボトルを使って遊んでいて、より「本番」のWSGIサーバーgunicornに切り替えたいと思っていました。これが私の設定です:

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)

そして、これが私のProcfileです:

web: gunicorn SimpleServer:app -w 3

SimpleServer.pyアプリケーションでワーカー数などを設定して、または設定せずにProcfileを試しました。

ローカルマシンでは、アプリにworkers = 3があり、 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

しかし、フォアマンスタートには問題があります。使用する設定に関係なく、次のようになります。

(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.

任意のアイデアをいただければ幸いです!)。

4

1 に答える 1

3

アプリを実行するために gunicorn を開始し、Bottle の「実行」を使用して別のサーバーを生成します (少なくとも Heroku 上では)。エラーが発生する理由は、最初のサーバーがポート 5000 を使用し、2 番目のサーバーがそれにアクセスできないためです。サーバー自体を作成する必要があるボトル アプリ (python SimpleServer.py) を実行してみてください。また、'app' を run に渡すと、http サーバーはアプリの別のコピーを生成します (別の gunicorn サーバーを生成します)。それを削除するだけです。

run(server='gunicorn', host='0.0.0.0', port=int(os.environ.get("PORT", 5000)), debug=True, workers=X)

python SimpleServer.py

必要なものはすべて揃っているはずです。

于 2013-02-03T00:59:49.197 に答える