本文整理汇总了Python中cherrypy.wsgiserver.CherryPyWSGIServer.stop方法的典型用法代码示例。如果您正苦于以下问题:Python CherryPyWSGIServer.stop方法的具体用法?Python CherryPyWSGIServer.stop怎么用?Python CherryPyWSGIServer.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cherrypy.wsgiserver.CherryPyWSGIServer
的用法示例。
在下文中一共展示了CherryPyWSGIServer.stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_server
# 需要导入模块: from cherrypy.wsgiserver import CherryPyWSGIServer [as 别名]
# 或者: from cherrypy.wsgiserver.CherryPyWSGIServer import stop [as 别名]
def start_server(options, settings):
"""
Start CherryPy server
"""
if options['daemonize'] and options['server_user'] and options['server_group']:
#ensure the that the daemon runs as specified user
change_uid_gid(options['server_user'], options['server_group'])
from cherrypy.wsgiserver import CherryPyWSGIServer as Server
from django.core.handlers.wsgi import WSGIHandler
from django.core.servers.basehttp import AdminMediaHandler
app = AdminMediaHandler(WSGIHandler())
server = Server(
(options['host'], int(options['port'])),
app,
int(options['threads']),
options['server_name']
)
if options['ssl_certificate'] and options['ssl_private_key']:
server.ssl_certificate = options['ssl_certificate']
server.ssl_private_key = options['ssl_private_key']
try:
server.start()
except KeyboardInterrupt:
server.stop()
示例2: start_server
# 需要导入模块: from cherrypy.wsgiserver import CherryPyWSGIServer [as 别名]
# 或者: from cherrypy.wsgiserver.CherryPyWSGIServer import stop [as 别名]
def start_server(options):
"""
Start CherryPy server. DEPRICATED>>>>
Saving this function for future readers to use.
"""
if options['daemonize'] and options['server_user'] and options['server_group']:
#ensure the that the daemon runs as specified user
change_uid_gid(options['server_user'], options['server_group'])
from cherrypy.wsgiserver import CherryPyWSGIServer as Server
from django.core.handlers.wsgi import WSGIHandler
server = Server(
(options['host'], int(options['port'])),
WSGIHandler(),
int(options['threads']),
options['server_name']
)
if options['ssl_certificate'] and options['ssl_private_key']:
server.ssl_certificate = options['ssl_certificate']
server.ssl_private_key = options['ssl_private_key']
try:
server.start()
except KeyboardInterrupt:
server.stop()
示例3: __call__
# 需要导入模块: from cherrypy.wsgiserver import CherryPyWSGIServer [as 别名]
# 或者: from cherrypy.wsgiserver.CherryPyWSGIServer import stop [as 别名]
def __call__(self, address=None):
"""
start development web server
address - where to serve, [interface:]port
"""
if address is not None:
interface = '127.0.0.1'
port = address
if ':' in port:
interface, port = port.split(':')
try:
port = int(port)
except:
raise InvalidArguments('Unable to parse port "%s"' % address)
else:
interface = '127.0.0.1'
port = DEFAULT_RADAR_PORT
from cherrypy.wsgiserver import CherryPyWSGIServer as WSGIServer
app = RequestLogger(make_app(self.config))
cherry_opts = config_section('cherrypy', self.config)
server = WSGIServer((interface, port), app, **cherry_opts)
print "* serving on %s:%d" % (interface, port)
try:
server.start()
except KeyboardInterrupt:
server.stop()
示例4: run
# 需要导入模块: from cherrypy.wsgiserver import CherryPyWSGIServer [as 别名]
# 或者: from cherrypy.wsgiserver.CherryPyWSGIServer import stop [as 别名]
def run(self, handler):
server = CherryPyWSGIServer((self.host, self.port), handler)
server.ssl_adapter = pyOpenSSLAdapter(CONSTANTS['certificate'], CONSTANTS['key'])
try:
server.start()
finally:
server.stop()
示例5: CherryPyLiveServerPlugin
# 需要导入模块: from cherrypy.wsgiserver import CherryPyWSGIServer [as 别名]
# 或者: from cherrypy.wsgiserver.CherryPyWSGIServer import stop [as 别名]
class CherryPyLiveServerPlugin(AbstractLiveServerPlugin):
"""Live server plugin using cherrypy instead of the django server,
that got its issues. Original code by Mikeal Rogers, released under
Apache License.
"""
name = 'cherrypyliveserver'
activation_parameter = '--with-cherrypyliveserver'
def start_server(self, address='0.0.0.0', port=8000, serve_static=True):
from cherrypy.wsgiserver import CherryPyWSGIServer
from threading import Thread
_application = AdminMediaHandler(WSGIHandler())
if serve_static:
_application = StaticFilesHandler(_application)
def application(environ, start_response):
environ['PATH_INFO'] = environ['SCRIPT_NAME'] + \
environ['PATH_INFO']
return _application(environ, start_response)
self.httpd = CherryPyWSGIServer((address, port), application,
server_name='django-test-http')
self.httpd_thread = Thread(target=self.httpd.start)
self.httpd_thread.start()
# FIXME: This could be avoided by passing self to thread class starting
# django and waiting for Event lock
time.sleep(.5)
def stop_server(self):
self.httpd.stop()
示例6: main
# 需要导入模块: from cherrypy.wsgiserver import CherryPyWSGIServer [as 别名]
# 或者: from cherrypy.wsgiserver.CherryPyWSGIServer import stop [as 别名]
def main():
root_path = gettempdir()
provider = FilesystemProvider(root_path)
config = {
"provider_mapping": {"/": provider},
"http_authenticator": {
"domain_controller": None # None: dc.simple_dc.SimpleDomainController(user_mapping)
},
"simple_dc": {"user_mapping": {"*": True}}, # anonymous access
"verbose": 1,
"enable_loggers": [],
"property_manager": True, # True: use property_manager.PropertyManager
"lock_manager": True, # True: use lock_manager.LockManager
}
app = WsgiDAVApp(config)
# For an example, use CherryPy
from cherrypy.wsgiserver import CherryPyWSGIServer
server = CherryPyWSGIServer(
bind_addr=(config["host"], config["port"]),
wsgi_app=app,
server_name="WsgiDAV/{} {}".format(__version__, CherryPyWSGIServer.version),
)
try:
server.start()
except KeyboardInterrupt:
print("Caught Ctrl-C, shutting down...")
finally:
server.stop()
示例7: start_server
# 需要导入模块: from cherrypy.wsgiserver import CherryPyWSGIServer [as 别名]
# 或者: from cherrypy.wsgiserver.CherryPyWSGIServer import stop [as 别名]
def start_server(options):
"""
Start CherryPy server
"""
if options['daemonize'] and options['server_user'] and options['server_group']:
#ensure the that the daemon runs as specified user
change_uid_gid(options['server_user'], options['server_group'])
try:
from cherrypy.wsgiserver import CherryPyWSGIServer as Server
except ImportError:
try:
from wsgiserver import CherryPyWSGIServer as Server
except ImportError:
from cpserver.wsgiserver import CherryPyWSGIServer as Server
from django.core.handlers.wsgi import WSGIHandler
server = Server(
(options['host'], int(options['port'])),
WSGIHandler(),
int(options['threads']),
options['server_name'],
request_queue_size=int(options['request_queue_size'])
)
if options['ssl_certificate'] and options['ssl_private_key']:
server.ssl_certificate = options['ssl_certificate']
server.ssl_private_key = options['ssl_private_key']
try:
server.start()
except KeyboardInterrupt:
server.stop()
示例8: run
# 需要导入模块: from cherrypy.wsgiserver import CherryPyWSGIServer [as 别名]
# 或者: from cherrypy.wsgiserver.CherryPyWSGIServer import stop [as 别名]
def run(self, handler):
self.options['bind_addr'] = (self.host, self.port)
self.options['wsgi_app'] = handler
certfile = self.options.get('certfile')
if certfile or 'certfile' in self.options:
del self.options['certfile']
keyfile = self.options.get('keyfile')
if keyfile or 'keyfile' in self.options:
del self.options['keyfile']
server = CherryPyWSGIServer(**self.options)
if keyfile and certfile:
LOGGER.info("Start using HTTPS")
server.ssl_adapter = pyOpenSSLAdapter(certfile, keyfile, None)
context = ssl.Context(ssl.SSLv23_METHOD)
context.set_cipher_list('HIGH')
context.use_privatekey_file(keyfile)
context.use_certificate_file(certfile)
server.ssl_adapter.context = context
else:
LOGGER.info("Start using HTTP")
try:
server.start()
finally:
server.stop()
示例9: inner_run
# 需要导入模块: from cherrypy.wsgiserver import CherryPyWSGIServer [as 别名]
# 或者: from cherrypy.wsgiserver.CherryPyWSGIServer import stop [as 别名]
def inner_run():
if ssl_private_key and ssl_certificate:
print "MSS server is running at https://%s:%s/" % (addr, port)
else:
print "MSS server is running at http://%s:%s/" % (addr, port)
if settings.DEBUG:
print "Devel mode is ON"
print "Quit the server with %s." % quit_command
app = WSGIHandler()
path = {}
if show_log:
logged_app = TransLogger(app)
path['/'] = logged_app
else:
path['/'] = app
path[settings.MEDIA_URL] = MediaHandler(settings.MEDIA_ROOT)
dispatcher = WSGIPathInfoDispatcher(path)
server = CherryPyWSGIServer((addr, int(port)), dispatcher, threads)
if ssl_private_key and ssl_certificate:
from cherrypy.wsgiserver.ssl_pyopenssl import pyOpenSSLAdapter
server.ssl_adapter = pyOpenSSLAdapter(ssl_certificate, ssl_private_key, None)
try:
server.start()
except KeyboardInterrupt:
server.stop()
sys.exit(0)
示例10: handle
# 需要导入模块: from cherrypy.wsgiserver import CherryPyWSGIServer [as 别名]
# 或者: from cherrypy.wsgiserver.CherryPyWSGIServer import stop [as 别名]
def handle(self, **options):
# Determine the port number
if 'port' in options:
port = int(options['port'] or settings.PORT)
else:
port = settings.PORT
# Determine the number of threads
if 'threads' in options:
threads = int(options['threads'] or 25)
if threads < 1:
raise Exception("Invalid number of threads: %s" % threads)
else:
threads = 25
# Determine the IP-address to listen on:
# - either as command line argument
# - either 0.0.0.0 by default, which means all active IPv4 interfaces
address = 'address' in options and options['address'] or '0.0.0.0'
# Validate the address and port number
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind( (address, port) )
s.close()
except socket.error as e:
raise Exception("Invalid address '%s' and/or port '%s': %s" % (address, port, e))
# Print a header message
hostname = socket.getfqdn()
print('Starting frePPLe %s web server\n' % VERSION)
print('To access the server, point your browser to either of the following URLS:')
if address == '0.0.0.0':
print(' http://%s:%s/' % (hostname, port))
for ip in socket.gethostbyname_ex(socket.gethostname())[2]:
print(' http://%s:%s/' % (ip, port))
else:
print(' http://%s:%s/' % (address, port))
print('\nThree users are created by default: "admin", "frepple" and "guest" (the default password is equal to the user name)\n')
print('Quit the server with CTRL-C.\n')
# Start a separate thread that will check for updates
# We don't wait for it to finish
CheckUpdates().start()
# Run the WSGI server
server = CherryPyWSGIServer(
(address, port),
StaticFilesHandler(WSGIHandler()),
numthreads=threads
)
# Want SSL support? Just set these attributes apparently, but I haven't tested or verified this
# server.ssl_certificate = <filename>
# server.ssl_private_key = <filename>
try:
server.start()
except KeyboardInterrupt:
server.stop()
示例11: Command
# 需要导入模块: from cherrypy.wsgiserver import CherryPyWSGIServer [as 别名]
# 或者: from cherrypy.wsgiserver.CherryPyWSGIServer import stop [as 别名]
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option("-h", "--host", dest="host", default=DEFAULT_HOST),
make_option("-p", "--port", dest="port", default=DEFAULT_PORT),
make_option("-d", "--daemon", dest="daemonize", action="store_true"),
)
requires_model_validation = False
def handle(self, *args, **options):
self.options = options
self.server = CherryPyWSGIServer((options["host"], options["port"]), WSGIHandler())
self.pidfile = os.path.join(settings.PROJECT_ROOT, "logs/wsgi.pid")
try:
action = args[0]
except IndexError:
print "You must provide an action. Possible actions are start, stop and restart."
raise SystemExit
if action == "start":
print "Running %s:%d" % (options["host"], options["port"])
self.daemonize()
self.start()
elif action == "stop":
pid = open(self.pidfile, "r").read()
self.stop(pid)
elif action == "restart":
pid = open(self.pidfile, "r").read()
self.restart(pid)
def daemonize(self):
if self.options["daemonize"]:
daemonize()
def start(self):
writepid(self.pidfile)
try:
self.server.start()
except KeyboardInterrupt:
# likely not a daemon so make sure to shutdown properly.
self.server.stop()
def stop(self, pid):
os.kill(int(pid), signal.SIGHUP)
def restart(self, pid):
self.stop(pid)
self.daemonize()
self.start()
def create_parser(self, prog_name, subcommand):
"""
Create and return the ``OptionParser`` which will be used to
parse the arguments to this command.
"""
return OptionParser(prog=prog_name, usage=self.usage(subcommand),
version = self.get_version(),
option_list = self.option_list,
conflict_handler = "resolve")
示例12: run
# 需要导入模块: from cherrypy.wsgiserver import CherryPyWSGIServer [as 别名]
# 或者: from cherrypy.wsgiserver.CherryPyWSGIServer import stop [as 别名]
def run(self, handler):
server = CherryPyWSGIServer((self.host, self.port), handler)
server.ssl_adapter = \
pyOpenSSLAdapter(RestConfig.get('ssl','certificate'),
RestConfig.get('ssl', 'key'))
try:
server.start()
finally:
server.stop()
示例13: launch_server_cherrypy
# 需要导入模块: from cherrypy.wsgiserver import CherryPyWSGIServer [as 别名]
# 或者: from cherrypy.wsgiserver.CherryPyWSGIServer import stop [as 别名]
def launch_server_cherrypy(host, port, app):
"""use cherrypy's wsgiserver, a multithreaded scallable server"""
from cherrypy.wsgiserver import CherryPyWSGIServer
server = CherryPyWSGIServer((host, port), app)
logging.info("Starting CherryPy server, listening on port %s", port)
try:
server.start()
except KeyboardInterrupt:
server.stop()
示例14: Command
# 需要导入模块: from cherrypy.wsgiserver import CherryPyWSGIServer [as 别名]
# 或者: from cherrypy.wsgiserver.CherryPyWSGIServer import stop [as 别名]
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option("-h", "--host", dest="host", default=DEFAULT_HOST),
make_option("-p", "--port", dest="port", default=DEFAULT_PORT, type="int"),
make_option("-d", "--daemon", dest="daemonize", action="store_true"),
)
requires_model_validation = False
def handle(self, *args, **options):
self.server = CherryPyWSGIServer((options["host"], options["port"]), WSGIHandler())
self.pidfile = settings.APP_DIR.joinpath("wsgi.pid")
try:
action = args[0]
except IndexError:
action = "start"
if options["daemonize"]:
daemonize()
if action == "start":
self.start(create_pid_file=options["daemonize"])
elif action == "stop":
pid = open(self.pidfile, "r").read()
self.stop(pid)
elif action == "restart":
pid = open(self.pidfile, "r").read()
self.restart(pid)
def start(self, create_pid_file=False):
if create_pid_file:
writepid(self.pidfile)
try:
self.server.start()
except KeyboardInterrupt:
# likely not a daemon so make sure to shutdown properly.
self.server.stop()
def stop(self, pid):
os.kill(int(pid), signal.SIGHUP)
def restart(self, pid):
self.stop(pid)
self.start()
def create_parser(self, prog_name, subcommand):
"""
Create and return the ``OptionParser`` which will be used to
parse the arguments to this command.
"""
return OptionParser(
prog=prog_name,
usage=self.usage(subcommand),
version=self.get_version(),
option_list=self.option_list,
conflict_handler="resolve",
)
示例15: start
# 需要导入模块: from cherrypy.wsgiserver import CherryPyWSGIServer [as 别名]
# 或者: from cherrypy.wsgiserver.CherryPyWSGIServer import stop [as 别名]
def start(self):
from cherrypy.wsgiserver import CherryPyWSGIServer
hostname = self.config['server_host']['host']
port = int(self.config['server_host']['port'])
scheme = self.config['server_host']['scheme']
server = CherryPyWSGIServer((hostname, port), self.server)
try:
logging.debug('starting CherryPy at %s://%s:%s',
scheme, hostname, port)
print "Starting CherryPy at %s://%s:%s" % (scheme, hostname, port)
server.start()
except KeyboardInterrupt:
server.stop()