【发布时间】:2015-11-16 22:19:47
【问题描述】:
我这里有一个 Python 程序。 它使用 CherryPy 创建服务器。
# coding:utf-8
import os.path
import cherrypy
from app import application
def main():
try:
currentDir_s = os.path.dirname(os.path.abspath(__file__))
except:
currentDir_s = os.path.dirname(os.path.abspath(sys.executable))
cherrypy.Application.currentDir_s = currentDir_s
configFileName_s = 'server.conf'
if os.path.exists(configFileName_s) == False:
configFileName_s = None
cherrypy.engine.autoreload.unsubscribe()
cherrypy.engine.timeout_monitor.unsubscribe()
cherrypy.quickstart(application.Application_cl(), config=configFileName_s)
if __name__ == '__main__':
main()
并在“server.conf”中配置服务器:
[global]
tools.log_headers.on: True
tools.sessions.on: False
tools.encode.on: True
tools.encode.encoding:"utf-8"
server.socket_port: 8080
server.socket_timeout:60
server.thread_pool: 10
server.environment: "production"
log.screen: True
[/]
tools.staticdir.root: cherrypy.Application.currentDir_s
tools.staticdir.on = True
tools.staticdir.dir = '.'
有一件事,我不明白,这一行(python代码中的第13行):
cherrypy.Application.currentDir_s = currentDir_s
我在互联网上搜索过这个,但我找不到任何东西。 “cherrypy.Application”有什么作用?为什么我必须做这个作业(cherrypy.Application.currentDir_s = currentDir_s)?
【问题讨论】: