gpt4 book ai didi

python - CherryPy 无法启动

转载 作者:行者123 更新时间:2023-11-30 23:22:18 26 4
gpt4 key购买 nike

我在启动 CherryPy 时遇到一些问题,我不明白为什么我总是收到此错误。这是版本和带有日志输出的相关代码。

Python 2.7.6CherryPy 3.5.0(通过 PIP)

CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_DIR = os.path.join(CURRENT_DIR, "static")
CONFIG = {
'/static': {
'tools.staticdir.on': True,
'tools.staticdir.dir': STATIC_DIR
}
}

Daemonizer(cherrypy.engine).subscribe() # When we start, do it as a daemon process
cherrypy.config.update({'server.socket_host': '127.0.0.1','server.socket_port': 8080,'log.error_file': 'site.log'}) # Listen on all local IPs (default is 8080)
cherrypy.tree.mount(MyWebServer(), '/', config=CONFIG) # Mount the app on the root
cherrypy.engine.start()

这是日志输出:

[05/Jul/2014:10:28:01] ENGINE Bus STARTING
[05/Jul/2014:10:28:01] ENGINE Forking once.
[05/Jul/2014:10:28:01] ENGINE Forking twice.
[05/Jul/2014:10:28:01] ENGINE Daemonized to PID: 21464
[05/Jul/2014:10:28:01] ENGINE Started monitor thread 'Monitor'.
[05/Jul/2014:10:28:01] ENGINE Started monitor thread 'Autoreloader'.
[05/Jul/2014:10:28:01] ENGINE Started monitor thread 'Monitor'.
[05/Jul/2014:10:28:01] ENGINE Started monitor thread 'Monitor'.
[05/Jul/2014:10:28:01] ENGINE Started monitor thread 'Monitor'.
[05/Jul/2014:10:28:01] ENGINE Started monitor thread '_TimeoutMonitor'.
[05/Jul/2014:10:28:01] ENGINE Error in 'start' listener <bound method Server.start of <cherrypy._cpserver.Server object at 0x10cf2d190>>
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/cherrypy/process/wspbus.py", line 205, in publish
output.append(listener(*args, **kwargs))
File "/Library/Python/2.7/site-packages/cherrypy/_cpserver.py", line 167, in start
self.httpserver, self.bind_addr = self.httpserver_from_self()
File "/Library/Python/2.7/site-packages/cherrypy/_cpserver.py", line 158, in httpserver_from_self
httpserver = _cpwsgi_server.CPWSGIServer(self)
File "/Library/Python/2.7/site-packages/cherrypy/_cpwsgi_server.py", line 43, in __init__
accepted_queue_timeout=self.server_adapter.accepted_queue_timeout,
TypeError: __init__() got an unexpected keyword argument 'accepted_queue_size'

[05/Jul/2014:10:28:01] ENGINE Shutting down due to error in start listener:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/cherrypy/process/wspbus.py", line 243, in start
self.publish('start')
File "/Library/Python/2.7/site-packages/cherrypy/process/wspbus.py", line 223, in publish
raise exc
ChannelFailures: TypeError("__init__() got an unexpected keyword argument 'accepted_queue_size'",)

[05/Jul/2014:10:28:01] ENGINE Bus STOPPING
[05/Jul/2014:10:28:01] ENGINE HTTP Server None already shut down
[05/Jul/2014:10:28:01] ENGINE Stopped thread '_TimeoutMonitor'.
[05/Jul/2014:10:28:01] ENGINE Stopped thread 'Monitor'.
[05/Jul/2014:10:28:01] ENGINE Stopped thread 'Monitor'.
[05/Jul/2014:10:28:01] ENGINE Stopped thread 'Autoreloader'.
[05/Jul/2014:10:28:01] ENGINE Stopped thread 'Monitor'.
[05/Jul/2014:10:28:01] ENGINE Stopped thread 'Monitor'.
[05/Jul/2014:10:28:01] ENGINE Bus STOPPED
[05/Jul/2014:10:28:01] ENGINE Bus EXITING
[05/Jul/2014:10:28:01] ENGINE Bus EXITED

最佳答案

我猜 Daemonizer 的存在表明您实际上是在询问 CherryPy 部署。

首先,cherrypy.engine.start() 不足以启动CherryPy。看一下 cherrypy.quickstart 的最小例程。我把它放在 __name__ == '__main__' 条件下。它允许您直接从 shell 执行脚本。

其次,您可能不应该直接在应用程序代码中处理 Daemonizer 插件(以及 PIDFileDropPrivileges 等)。有cherryd应该处理系统的东西。

您可以通过cherryd -i static运行下面的代码(放入static.py,cd到包含的目录)。它将在前台启动您的应用程序。 cherryd -d -i static 将守护您的应用程序。

#!/usr/bin/env python
# -*- coding: utf-8 -*-


import os

import cherrypy


path = os.path.abspath(os.path.dirname(__file__))
config = {
'global' : {
'server.socket_host' : '127.0.0.1',
'server.socket_port' : 8080,
'server.thread_pool' : 4
},
'/static' : {
'tools.staticdir.on' : True,
'tools.staticdir.dir' : os.path.join(path, 'static')
}
}

class App:

@cherrypy.expose
def index(self):
return 'Your dynamic stuff'


cherrypy.tree.mount(App(), '/', config)


if __name__ == '__main__':
cherrypy.engine.signals.subscribe()
cherrypy.engine.start()
cherrypy.engine.block()

我编写了完整的CherryPy部署教程,cherrypy-webapp-skeleton , 几年前。如果您需要完整的图片,请看一下。

关于python - CherryPy 无法启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24587472/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com