Browse Source

Make server check that the db object has been wrapped in a serializer

It's only the server that calls it in multiple threads.
tags/nilmdb-1.2
Jim Paris 10 years ago
parent
commit
7fce305a1d
2 changed files with 10 additions and 0 deletions
  1. +5
    -0
      nilmdb/server/server.py
  2. +5
    -0
      tests/test_nilmdb.py

+ 5
- 0
nilmdb/server/server.py View File

@@ -383,6 +383,11 @@ class Server(object):

self.embedded = embedded
self.db = db
if not getattr(db, "_thread_safe", None):
raise KeyError("Database object " + str(db) + " doesn't claim "
"to be thread safe. You should pass "
"nilmdb.utils.serializer_proxy(NilmDB, args) "
"rather than NilmDB(args).")

# Build up global server configuration
cherrypy.config.update({


+ 5
- 0
tests/test_nilmdb.py View File

@@ -111,6 +111,11 @@ class TestBlockingServer(object):
self.db.close()

def test_blocking_server(self):
# Server should fail if the database doesn't have a "_thread_safe"
# property.
with assert_raises(KeyError):
nilmdb.Server(object())

# Start web app on a custom port
self.server = nilmdb.Server(self.db, host = "127.0.0.1",
port = 12380, stoppable = True)


Loading…
Cancel
Save