diff --git a/jupyterhub/app.py b/jupyterhub/app.py index edf34901..6bb62a1c 100644 --- a/jupyterhub/app.py +++ b/jupyterhub/app.py @@ -16,7 +16,6 @@ import shutil import signal import sys from textwrap import dedent -import threading from urllib.parse import urlparse if sys.version_info[:2] < (3, 3): @@ -423,7 +422,6 @@ class JupyterHub(Application): @observe('base_url') def _update_hub_prefix(self, change): """add base URL to hub prefix""" - base_url = change['new'] self.hub_prefix = self._hub_prefix_default() cookie_secret = Bytes( @@ -813,15 +811,6 @@ class JupyterHub(Application): # store the loaded trait value self.cookie_secret = secret - # thread-local storage of db objects - _local = Instance(threading.local, ()) - - @property - def db(self): - if not hasattr(self._local, 'db'): - self._local.db = scoped_session(self.session_factory)() - return self._local.db - def init_db(self): """Create the database connection""" self.log.debug("Connecting to db: %s", self.db_url) @@ -833,7 +822,7 @@ class JupyterHub(Application): **self.db_kwargs ) # trigger constructing thread local db property - _ = self.db + self.db = scoped_session(self.session_factory)() except OperationalError as e: self.log.error("Failed to connect to db: %s", self.db_url) self.log.debug("Database error was:", exc_info=True) diff --git a/jupyterhub/user.py b/jupyterhub/user.py index 720c0897..7d04185d 100644 --- a/jupyterhub/user.py +++ b/jupyterhub/user.py @@ -98,27 +98,7 @@ class User(HasTraits): if self.orm_user: return inspect(self.orm_user).session - @observe('db') - def _db_changed(self, change): - """Changing db session reacquires ORM User object""" - # db session changed, re-get orm User - db = change.new - if self._user_id is not None: - # fetch our orm.User from the new db session - self.orm_user = db.query(orm.User).filter(orm.User.id == self._user_id).first() - # update our spawners' ORM objects with the new session, - # which can be found on our new orm_user. - for name, spawner in self.spawners.items(): - spawner.orm_spawner = self.orm_user.orm_spawners[name] - - _user_id = None orm_user = Any(allow_none=True) - @observe('orm_user') - def _orm_user_changed(self, change): - if change.new: - self._user_id = change.new.id - else: - self._user_id = None @property def authenticator(self):