Connect to default kernel from SessionContext

I am trying to use SessionContext object in my extension to connect to a kernel so that I can run some Python code based on user actions in my extension’s widgets. I followed the example code in extension-examples/kernel-messaging at master · jupyterlab/extension-examples · GitHub but this shows up a pop-up to select the kernel everytime the extension is activated. How do I connect to the default kernel instead of showing the pop-up for kernel selection?

Thanks,
Rakesh.

1 Like

I actually figured it out - I had to pass ‘kernelPreference’ to the constructor of the SessionContext class with ‘autoStartDefault’ set to true like so:

this._sessionContext = new SessionContext({
            sessionManager: manager.sessions,
            specsManager: manager.kernelspecs,
            name: 'Example Extension',
            kernelPreference: {autoStartDefault:true}
          });
1 Like