CherryPy无法启动 [英] CherryPy won't start

查看:141
本文介绍了CherryPy无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在启动CherryPy时遇到了一些麻烦,我不知道为什么我总是收到此错误.这是带有日志输出的版本和相关代码.

I'm having some trouble starting CherryPy and I can't figure out why I keep getting this error. Here's the versions and the related code with log output.

Python 2.7.6CherryPy 3.5.0(通过PIP)

Python 2.7.6 CherryPy 3.5.0 (via 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 部署的问题.

I guess Daemonizer presence indicates you're actually asking about CherryPy deployment.

首先, cherrypy.engine.start()不足以启动 CherryPy .看一下 cherrypy.quickstart 的最小例程.我将其置于 __ name__ =='__main __'条件下.它使您可以直接从Shell执行脚本.

First, cherrypy.engine.start() is not enough to start CherryPy. Take a look at cherrypy.quickstart for the minimal routine. I put it under __name__ == '__main__' condition. It allows you to directly execute the script from shell.

第二,您不应该直接在应用程序代码中处理 Daemonizer 插件(以及 PIDFile DropPrivileges 等).有 cherryd 应该处理系统内容.

Second, you shouldn't probably deal with Daemonizer plugin (and PIDFile, DropPrivileges, etc) directly in your application code. There's cherryd which should deal with system stuff.

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

You can run the code below (put in static.py, cd to the containing directory) by cherryd -i static. It will start your app in foreground. cherryd -d -i static will daemonize your app.

#!/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,几年前.看一看是否需要完整的图片.

I wrote a complete CherryPy deployment tutorial, cherrypy-webapp-skeleton, a couple of years ago. Take a look if you need a complete picture.

这篇关于CherryPy无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆