我正在为我的应用程序使用gunicorn自定义工作程序,但我正在努力启动该应用程序
我正在使用gunicorn -b 127.0.0.1:8080 filename:main
来启动应用程序
如何从自定义工作程序开始?
def number_of_workers():
return (multiprocessing.cpu_count() * 2) + 1
def handler_app(environ, start_response):
response_body = b'Works fine'
status = '200 OK'
response_headers = [
('Content-Type', 'text/plain'),
]
start_response(status, response_headers)
return [response_body]
class StandaloneApplication(gunicorn.app.base.BaseApplication):
def __init__(self, app, options=None):
self.options = options or {}
self.application = app
super(StandaloneApplication, self).__init__()
def load_config(self):
config = dict([(key, value) for key, value in iteritems(self.options)
if key in self.cfg.settings and value is not None])
for key, value in iteritems(config):
self.cfg.set(key.lower(), value)
def load(self):
return self.application
if __name__ == '__main__':
options = {
'bind': '%s:%s' % ('127.0.0.1', '8080'),
'workers': number_of_workers(),
}
StandaloneApplication(handler_app, options).run()
回溯(最近通话最近):文件 “ /home/pl900/.local/lib/python3.6/site-packages/gunicorn/workers/sync.py”, 135号线,在手柄中 self.handle_request(监听器,请求,客户端,地址)文件“ /home/pl900/.local/lib/python3.6/site-packages/gunicorn/workers/sync.py”, 第176行,在handle_request中 respiter = self.wsgi(environ,resp.start_response)TypeError:main()接受0个位置参数,但给出了2个