Browse Source

Run cherrypy always in "embedded" mode

Non-embedded mode is not used in the test suite or wsgi server;
it was an option in the standalong nilmdb-server script, but it's
really not necessary, and removing it gets rid of some untested
code.
tags/nilmdb-2.0.0
Jim Paris 1 year ago
parent
commit
7cbc0c11c3
3 changed files with 4 additions and 20 deletions
  1. +0
    -5
      nilmdb/scripts/nilmdb_server.py
  2. +3
    -7
      nilmdb/server/server.py
  3. +1
    -8
      nilmdb/server/serverutil.py

+ 0
- 5
nilmdb/scripts/nilmdb_server.py View File

@@ -39,14 +39,9 @@ def main():
db = nilmdb.utils.serializer_proxy(nilmdb.server.NilmDB)(args.database)

# Configure the server
if args.quiet:
embedded = True
else:
embedded = False
server = nilmdb.server.Server(db,
host = args.address,
port = args.port,
embedded = embedded,
force_traceback = args.traceback)

# Print info


+ 3
- 7
nilmdb/server/server.py View File

@@ -409,7 +409,6 @@ class Exiter(object):
class Server(object):
def __init__(self, db, host = '127.0.0.1', port = 8080,
stoppable = False, # whether /exit URL exists
embedded = True, # hide diagnostics and output, etc
fast_shutdown = False, # don't wait for clients to disconn.
force_traceback = False, # include traceback in all errors
basepath = '', # base URL path for cherrypy.tree
@@ -417,7 +416,6 @@ class Server(object):
# Save server version, just for verification during tests
self.version = nilmdb.__version__

self.embedded = embedded
self.db = db
if not getattr(db, "_thread_safe", None):
raise KeyError("Database object " + str(db) + " doesn't claim "
@@ -427,13 +425,12 @@ class Server(object):

# Build up global server configuration
cherrypy.config.update({
'environment': 'embedded',
'server.socket_host': host,
'server.socket_port': port,
'engine.autoreload.on': False,
'server.max_request_body_size': 8*1024*1024,
})
if self.embedded: # pragma: no branch (always taken in test suite)
cherrypy.config.update({ 'environment': 'embedded' })

# Build up application specific configuration
app_config = {}
@@ -491,7 +488,7 @@ class Server(object):
self.force_traceback)

def start(self, blocking = False, event = None):
cherrypy_start(blocking, event, self.embedded)
cherrypy_start(blocking, event)

def stop(self):
cherrypy_stop()
@@ -518,8 +515,7 @@ def wsgi_application(dbpath, basepath):
try:
db = nilmdb.utils.serializer_proxy(nilmdb.server.NilmDB)(dbpath)
_wsgi_server = nilmdb.server.Server(
db, embedded = True,
basepath = basepath.rstrip('/'))
db, basepath = basepath.rstrip('/'))
except Exception:
# Build an error message on failure
import pprint


+ 1
- 8
nilmdb/server/serverutil.py View File

@@ -143,17 +143,10 @@ def json_error_page(status, message, traceback, version,
return json.dumps(errordata, separators=(',',':'))

# Start/stop CherryPy standalone server
def cherrypy_start(blocking = False, event = False, embedded = False):
def cherrypy_start(blocking = False, event = False):
"""Start the CherryPy server, handling errors and signals
somewhat gracefully."""

if not embedded: # pragma: no cover
# Handle signals nicely
if hasattr(cherrypy.engine, "signal_handler"):
cherrypy.engine.signal_handler.subscribe()
if hasattr(cherrypy.engine, "console_control_handler"):
cherrypy.engine.console_control_handler.subscribe()

# Cherrypy stupidly calls os._exit(70) when it can't bind the
# port. At least try to print a reasonable error and continue
# in this case, rather than just dying silently (as we would


Loading…
Cancel
Save