How to use the jupyterhub.app.JupyterHub function in jupyterhub

To help you get started, we’ve selected a few jupyterhub examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyterhub / jupyterhub / jupyterhub / app.py View on Github external
self.log.exception("")
            self.exit(1)

    @classmethod
    def launch_instance(cls, argv=None):
        self = cls.instance()
        loop = IOLoop.current()
        loop.add_callback(self.launch_instance_async, argv)
        try:
            loop.start()
        except KeyboardInterrupt:
            print("\nInterrupted")


NewToken.classes.append(JupyterHub)
UpgradeDB.classes.append(JupyterHub)

main = JupyterHub.launch_instance

if __name__ == "__main__":
    main()
github jupyterhub / jupyterhub / jupyterhub / app.py View on Github external
def start(self):
        hub = JupyterHub(parent=self)
        hub.load_config_file(hub.config_file)
        if (hub.db_url.startswith('sqlite:///')):
            db_file = hub.db_url.split(':///', 1)[1]
            self._backup_db_file(db_file)
        self.log.info("Upgrading %s", hub.db_url)
        dbutil.upgrade(hub.db_url)
github jupyterhub / jupyterhub / jupyterhub / dbutil.py View on Github external
def shell(args=None):
    """Start an IPython shell hooked up to the jupyerhub database"""
    from .app import JupyterHub

    hub = JupyterHub()
    hub.load_config_file(hub.config_file)
    db_url = hub.db_url
    db = orm.new_session_factory(db_url, **hub.db_kwargs)()
    ns = {'db': db, 'db_url': db_url, 'orm': orm}

    import IPython

    IPython.start_ipython(args, user_ns=ns)
github jupyterhub / jupyterhub / jupyterhub / crypto.py View on Github external
def _config_default(self):
        # load application config by default
        from .app import JupyterHub

        if JupyterHub.initialized():
            return JupyterHub.instance().config
        else:
            return Config()
github jupyterhub / jupyterhub / jupyterhub / app.py View on Github external
try:
            loop.start()
        except KeyboardInterrupt:
            print("\nInterrupted")
        finally:
            if task.done():
                # re-raise exceptions in launch_instance_async
                task.result()
            loop.stop()
            loop.close()


NewToken.classes.append(JupyterHub)
UpgradeDB.classes.append(JupyterHub)

main = JupyterHub.launch_instance

if __name__ == "__main__":
    main()
github jupyterhub / jupyterhub / jupyterhub / apihandlers / hub.py View on Github external
def post(self):
        """POST /api/shutdown triggers a clean shutdown
        
        POST (JSON) parameters:
        
        - servers: specify whether single-user servers should be terminated
        - proxy: specify whether the proxy should be terminated
        """
        from ..app import JupyterHub

        app = JupyterHub.instance()

        data = self.get_json_body()
        if data:
            if 'proxy' in data:
                proxy = data['proxy']
                if proxy not in {True, False}:
                    raise web.HTTPError(
                        400, "proxy must be true or false, got %r" % proxy
                    )
                app.cleanup_proxy = proxy
            if 'servers' in data:
                servers = data['servers']
                if servers not in {True, False}:
                    raise web.HTTPError(
                        400, "servers must be true or false, got %r" % servers
                    )
github jupyterhub / jupyterhub / jupyterhub / crypto.py View on Github external
def _config_default(self):
        # load application config by default
        from .app import JupyterHub

        if JupyterHub.initialized():
            return JupyterHub.instance().config
        else:
            return Config()
github jupyterhub / jupyterhub / jupyterhub / alembic / env.py View on Github external
from alembic import context
from sqlalchemy import engine_from_config
from sqlalchemy import pool

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
if 'jupyterhub' in sys.modules:
    from traitlets.config import MultipleInstanceError
    from jupyterhub.app import JupyterHub

    app = None
    if JupyterHub.initialized():
        try:
            app = JupyterHub.instance()
        except MultipleInstanceError:
            # could have been another Application
            pass
    if app is not None:
        alembic_logger = logging.getLogger('alembic')
        alembic_logger.propagate = True
        alembic_logger.parent = app.log
    else:
        fileConfig(config.config_file_name, disable_existing_loggers=False)
else:
    fileConfig(config.config_file_name)

# add your model's MetaData object here for 'autogenerate' support
from jupyterhub import orm