How to use the @jupyterlab/services.Session.listRunning function in @jupyterlab/services

To help you get started, we’ve selected a few @jupyterlab/services 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 jupyterlab / jupyterlab-data-explorer / jupyterlab / packages / tooltip-extension / src / index.ts View on Github external
if (oldSession) {
            delete activeSessions[file.id];
            oldSession.dispose();
          }
          const session = sessions.connectTo(model);
          activeSessions[file.id] = session;
        } else {
          const session = activeSessions[file.id];
          if (session) {
            session.dispose();
            delete activeSessions[file.id];
          }
        }
      });
    };
    void Session.listRunning().then(models => {
      onRunningChanged(sessions, models);
    });
    sessions.runningChanged.connect(onRunningChanged);

    // Clean up after a widget when it is disposed
    editorTracker.widgetAdded.connect((sender, widget) => {
      widget.disposed.connect(w => {
        const session = activeSessions[w.id];
        if (session) {
          session.dispose();
          delete activeSessions[w.id];
        }
      });
    });

    // Add tooltip launch command.
github jupyterlab / jupyterlab / packages / docmanager / src / actions.ts View on Github external
function stopIfNeeded(manager: IServiceManager, path: string): Promise {
    return Session.listRunning().then(sessions => {
      const matches = sessions.filter(value => value.notebook.path === path);
      if (matches.length === 1) {
        const id = matches[0].id;
        return manager.sessions.shutdown(id).catch(() => { /* no-op */ });
      }
    }).catch(() => Promise.resolve(void 0)); // Always succeed.
  }
}
github jupyterlab / jupyterlab / packages / completer-extension / src / index.ts View on Github external
}
          const session = sessions.connectTo(model);
          handler.connector = new CompletionConnector({ session, editor });
          activeSessions[widget.id] = session;
        } else {
          // If we didn't find a match, make sure
          // the connector is the contextConnector and
          // dispose of any previous connection.
          handler.connector = contextConnector;
          if (oldSession) {
            delete activeSessions[widget.id];
            oldSession.dispose();
          }
        }
      };
      void Session.listRunning().then(models => {
        onRunningChanged(sessions, models);
      });
      sessions.runningChanged.connect(onRunningChanged);

      // Initially create the handler with the contextConnector.
      // If a kernel session is found matching this file editor,
      // it will be replaced in onRunningChanged().
      const handler = manager.register({
        connector: contextConnector,
        editor,
        parent: widget
      });

      // When the widget is disposed, do some cleanup.
      widget.disposed.connect(() => {
        sessions.runningChanged.disconnect(onRunningChanged);
github jupyterlab / jupyterlab-data-explorer / packages / completer-extension / src / index.ts View on Github external
}
          const session = sessions.connectTo(model);
          handler.connector = new CompletionConnector({ session, editor });
          activeSessions[widget.id] = session;
        } else {
          // If we didn't find a match, make sure
          // the connector is the contextConnector and
          // dispose of any previous connection.
          handler.connector = contextConnector;
          if (oldSession) {
            delete activeSessions[widget.id];
            oldSession.dispose();
          }
        }
      };
      void Session.listRunning().then(models => {
        onRunningChanged(sessions, models);
      });
      sessions.runningChanged.connect(onRunningChanged);

      // Initially create the handler with the contextConnector.
      // If a kernel session is found matching this file editor,
      // it will be replaced in onRunningChanged().
      const handler = manager.register({
        connector: contextConnector,
        editor,
        parent: widget
      });

      // When the widget is disposed, do some cleanup.
      widget.disposed.connect(() => {
        sessions.runningChanged.disconnect(onRunningChanged);
github jupyterlab / jupyterlab / packages / completer-extension / src / index.ts View on Github external
}
          const session = sessions.connectTo(model);
          handler.connector = new CompletionConnector({ session, editor });
          activeSessions[widget.id] = session;
        } else {
          // If we didn't find a match, make sure
          // the connector is the contextConnector and
          // dispose of any previous connection.
          handler.connector = contextConnector;
          if (oldSession) {
            delete activeSessions[widget.id];
            oldSession.dispose();
          }
        }
      };
      void Session.listRunning().then(models => {
        onRunningChanged(sessions, models);
      });
      sessions.runningChanged.connect(onRunningChanged);

      // Initially create the handler with the contextConnector.
      // If a kernel session is found matching this file editor,
      // it will be replaced in onRunningChanged().
      const handler = manager.register({
        connector: contextConnector,
        editor,
        parent: widget
      });

      // When the widget is disposed, do some cleanup.
      widget.disposed.connect(() => {
        sessions.runningChanged.disconnect(onRunningChanged);
github jupyterlab / jupyterlab / tests / test-services / src / session / session.spec.ts View on Github external
it('should yield a list of valid session models', async () => {
      const response = await Session.listRunning();
      const running = toArray(response);
      expect(running.length).to.greaterThan(0);
    });
github jupyterlab / jupyterlab / tests / test-services / src / session / session.spec.ts View on Github external
it('should fail for error response status', async () => {
      const serverSettings = getRequestHandler(500, {});
      const list = Session.listRunning(serverSettings);
      await expectFailure(list, '');
    });
  });
github timkpaine / nannotate / packages / core / src / datamanager.ts View on Github external
constructor(bind: AnnotateWidget, base = '', comm = false){
        this._annotate = bind;
        this._bind = bind.dataNode;
        let path1 = window.location.host;
        let path2 = window.location.pathname;

        if(comm){
            this._ws_type = 'comm';
            Session.listRunning().then(sessionModels => {
                for (let i=0; i {
                            console.log('comm msg');
                            let dat = msg['content']['data'];
                            let event = new MessageEvent('msg', {data:dat});
                            this.open(event);
                        };
                        this._ws.onClose = () => {
                            console.log('comm closed');
                            this.close(new CloseEvent('close'))
                        };
                        this._ws.open('opened');
github nteract / hydrogen / lib / ws-kernel-picker.js View on Github external
}
    }

    try {
      if (!specModels) {
        specModels = await Kernel.getSpecs(serverSettings);
      }

      const kernelSpecs = _.filter(specModels.kernelspecs, spec =>
        this._kernelSpecFilter(spec)
      );

      const kernelNames = _.map(kernelSpecs, specModel => specModel.name);

      try {
        let sessionModels = await Session.listRunning(serverSettings);
        sessionModels = sessionModels.filter(model => {
          const name = model.kernel ? model.kernel.name : null;
          return name ? kernelNames.includes(name) : true;
        });
        const items = sessionModels.map(model => {
          let name;
          if (model.path) {
            name = tildify(model.path);
          } else if (model.notebook && model.notebook.path) {
            name = tildify(model.notebook.path);
          } else {
            name = `Session ${model.id}`;
          }
          return { name, model, options: serverSettings };
        });
        items.unshift({
github JovianML / jovian-py / jovian / jovian_lab_ext / src / NBKernel.ts View on Github external
return new Promise(resolve => {
      Session.listRunning().then(
        (allSessions)=>{
          for (let i = 0; i < allSessions.length; i++){
            let session = allSessions[i];
            if (session.type.toLowerCase() == "notebook"){
              let NBnameFromSession = session.name;
              if (NBnameFromSession.toLowerCase() == this.currentNotebookName().toLowerCase()){
                resolve(Kernel.connectTo(session.kernel) as Kernel.IKernel);
              }
            }
          }
        }
      )
    });
  }