CherryPy won't start

瘦欲@ 提交于 2020-01-16 02:57:08

问题


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

here's the log output:

[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

回答1:


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

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.

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.

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

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



来源:https://stackoverflow.com/questions/24587472/cherrypy-wont-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!