2014-07-05 28 views
1

我在啓動CherryPy時遇到了一些麻煩,我無法弄清楚爲什麼我不斷收到此錯誤。以下是有日誌輸出的版本和相關代碼。CherryPy無法啓動

的Python 2.7.6 的CherryPy 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 

回答

3

我猜Daemonizer存在表明你實際上問CherryPy的部署。

首先,cherrypy.engine.start()是不夠啓動CherryPy。最低程序請看cherrypy.quickstart。我把它放在__name__ == '__main__'的條件下。它允許你直接從shell執行腳本。其次,你不應該直接在應用程序代碼中處理Daemonizer插件(和PIDFile,DropPrivileges等)。有cherryd這應該處理系統的東西。

您可以運行下面的代碼(將static.py,cd置於包含的目錄中)cherryd -i static。它會在前臺啓動你的應用程序。 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,前幾年。看看你是否需要一個完整的圖片。

+0

這似乎像一個魅力工作。雖然由於某種原因,當我通過pip安裝cherrypy時沒有安裝櫻桃,所以我只是從Google Code repo中抓取它:)。 –