nteract / hydrogen

:atom: Run code interactively, inspect data, and plot. All the power of Jupyter kernels, inside your favorite text editor.
https://nteract.gitbooks.io/hydrogen/
MIT License
3.92k stars 334 forks source link

Interrupting ZMQ kernels is unsupported on Windows #597

Open nikitakit opened 7 years ago

nikitakit commented 7 years ago

Hydrogen's "Interrupt Kernel" command is currently unsupported for ZMQ kernels on Windows. At the moment, the best workaround if you depend on this functionality is to install a notebook server and use only "remote" kernels.

The reason is that this command was designed to send SIGINT to the kernel process (i.e. the equivalent of typing Ctrl-C in a Unix terminal). Sending signals is not available on Windows.

Notebooks (and other kinds of remote kernels) don't have this issue because they have implemented an alternative using Windows OS APIs. Code links for reference: here, here, and here.

It would be ideal if Hydrogen also did this. Since no existing hydrogen developers have volunteered to write this functionality, I'm opening this issue to keep a record and invite contributions from the community. It shouldn't be too difficult to implement -- the major requirement is to actually have Windows installed for testing.

See also: #593

rgbkrk commented 7 years ago

Ref for the nteract notebook side: https://github.com/paulcbetts/spawn-rx/issues/11 (spawn-rx sets up a proper process group on Windows, we don't have a way to send signals though).

Foucl commented 7 years ago

The idea would be to recreate jupyter client's win_interrupt.py, which you linked above, with something like node-ffi? I'd be happy to give it a try (it would take a while, however).

rgbkrk commented 7 years ago

Yes please @Foucl! I don't think anyone is working on this and we don't have the expertise.

dataecstasy commented 6 years ago

Hi All, I am facing this issue while pressing Ctrl-C in the Atom editor. Please suggest something simple to circumvent this. I wasn't facing this issue earlier, not sure why this has occurred?

Appreciate the help. Snapshot is attached. image

Thanks, Vishal

lgeiger commented 6 years ago

Hydrogen shouldn't register a keybinding for ctrl-c. Could you check which package registers this key binding by executing "Key Binding Resolver: Toggle" from the command palette and then pressing ctrl-c?

dataecstasy commented 6 years ago

Rbox had registered the key binding. For now I uninstalled Rbox and things are normal.

Needed to know a clean and less messy way of running R code in atom.

lgeiger commented 6 years ago

Needed to know a clean and less messy way of running R code in atom.

You can run R code with hydrogen if you install the IR kernel: https://nteract.io/kernels/r

lgeiger commented 6 years ago

Oh OK cool, Rbox uses Hydrogen to execute code and adds some custom keybindings.

You can open a issue or a PR on their repo to remove the windows keybinding since it conflicts with the copy command.

dataecstasy commented 6 years ago

Thanks, Lukas. Will do.

With IR kernel, I'm good to run the R code. However, some of the commands kept on executing forever no way to terminate them. Secondly, Would I again need to re-install all the r libraries installed earlier, code isn't finding them anymore?

aviatesk commented 5 years ago

Hi, I'm currently working on this issue and trying to interrupt a kernel using this newly implemented kernel interrupt messaging feature

So far I could implement control socket and sending interrupt_request to it, but I got an error saying [IPKernelApp] ERROR | UNKNOWN CONTROL MESSAGE TYPE: 'interrupt_request'. I suspect this is because we now use Jupyter messaging specification of which version is lower than 5.3. Could you tell me how can I specify the messaging specification version ??

Or do you think this approach seems inappropriate this time ? I think potential pitfall will be that we have to set kernelspec interrupt_mode = message to work this and this can make code more complex than the original approach, which was proposed in the issue.

n-riesco commented 5 years ago

@aviatesk That error message comes from IPython. Judging by https://github.com/ipython/ipykernel/issues/309 , IPython doesn't implement interrupt_request.

aviatesk commented 5 years ago

@n-riesco Thank you for replying me back. Oh maybe they are still in the process for implementing this feature ? (https://github.com/QuantStack/xeus/issues/56)

So the best workaround for this still seems to implement Windows interrupt event listener like jupyter client has done within node.js ??

/cc @lgeiger @rgbkrk

n-riesco commented 5 years ago

@aviatesk

So the best workaround for this still seems to implement Windows interrupt event listener like jupyter client has done within node.js ??

I'm not aware of any node.js modules to access kernel32.CreateEvent and kernel32.SetEvent.


If anyone wants to experiment with a solution, this is the relevant portion of code:

https://github.com/nteract/hydrogen/blob/25d7951cb7a1d16db71485c61d2d0cf38bb44152/lib/zmq-kernel.js#L144-L153

wadethestealth commented 4 years ago

Here is some code I attempted to get working but couldn't (It is meant to be a port of jupyter's win_interrupt). I was using ffi: ^2.3.0. I don't know that much about native bindings or kernel32, so I only got so far. Maybe I or someone will come back to this and find my code helpful though, but there is clearly an error in it.

   // ref is '* as ref'; ffi is '* as ffi'; Struct is 'ref-struct'
    var handle = ref.types.void // we don't know what the layout of "myobj" looks like
    var handleRef = ref.refType(handle);
    var voidtype = ref.types.void // we don't know what the layout of "myobj" looks like
    var voidP = ref.refType(voidtype);
    console.log(voidP);
    var SECURITY_ATTRIBUTES = new Struct({
      nLength: ref.types.uint32,
      lpSecurityDescriptor: voidP,
      bInheritHandle: ref.types.bool
    });
    var security = ref.refType(SECURITY_ATTRIBUTES);
    console.log(security);
    var test = ffi.Library('kernel32', {
      'CreateEventA': [
        handleRef,
        [security, 'bool', 'bool', 'char']
      ]
    });
    console.log(test);
    var sec = new SECURITY_ATTRIBUTES({
      nLength: security.size,
      lpSecurityDescriptor: Buffer.alloc(0),
      bInheritHandle: true
    });
    console.log(sec);
    var returned = test.CreateEventA(sec.ref(), false, false, ' '); // <------- Fails the call with no info
    console.log(returned);

If we truly wanted to support interrupting kernels, I think the most lightweight way is to create our own native binding of c code that calls the kernel functions matching the jupyter interrupt_windows file. I think this is the most lightweight because node already supports native bindings unlike python and also we already have to build hydrogen anyways.

sschuldenzucker commented 3 years ago

It's been almost 4 years now and we're still waiting for a feature to interrupt a computation.

tmcdonough commented 2 years ago

Anyone find a solution here? If not, anyone know of any hydrogen alternatives? I really like the single line executing functionality but this lack of an interrupt is tough to get past.

sschuldenzucker commented 2 years ago

Mit aware of a workaround. I'm using VS Code or Pycharm on Windows now, they integrate with Jupyter in much the same way as hydrogen.

On Thu, Jan 27, 2022, 13:25 Tom @.***> wrote:

Anyone find a solution here? If not, anyone know of any hydrogen alternatives? I really like the single line executing functionality but this lack of an interrupt is tough to get past.

— Reply to this email directly, view it on GitHub https://github.com/nteract/hydrogen/issues/597#issuecomment-1023208065, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIMX2F5LTLPO7BZNC4NZFTUYFBWJANCNFSM4C5XJIIQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>