Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interrupting ZMQ kernels is unsupported on Windows #597

Open
nikitakit opened this issue Jan 25, 2017 · 17 comments
Open

Interrupting ZMQ kernels is unsupported on Windows #597

nikitakit opened this issue Jan 25, 2017 · 17 comments
Labels

Comments

@nikitakit
Copy link
Contributor

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
Copy link
Member

rgbkrk commented Jan 25, 2017

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

@lgeiger lgeiger added enhancement 🌟 New feature ideas windows labels Jan 26, 2017
@Foucl
Copy link

Foucl commented Jun 9, 2017

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
Copy link
Member

rgbkrk commented Jun 13, 2017

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

@dataecstasy
Copy link

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
Copy link
Member

lgeiger commented Dec 25, 2017

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
Copy link

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
Copy link
Member

lgeiger commented Dec 25, 2017

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
Copy link
Member

lgeiger commented Dec 25, 2017

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
Copy link

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
Copy link
Member

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
Copy link
Collaborator

@aviatesk That error message comes from IPython. Judging by ipython/ipykernel#309 , IPython doesn't implement interrupt_request.

@aviatesk
Copy link
Member

@n-riesco Thank you for replying me back. Oh maybe they are still in the process for implementing this feature ? (jupyter-xeus/xeus#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
Copy link
Collaborator

@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:

hydrogen/lib/zmq-kernel.js

Lines 144 to 153 in 25d7951

interrupt() {
if (process.platform === "win32") {
atom.notifications.addWarning("Cannot interrupt this kernel", {
detail: "Kernel interruption is currently not supported in Windows."
});
} else {
log("ZMQKernel: sending SIGINT");
this.kernelProcess.kill("SIGINT");
}
}

@wadethestealth
Copy link
Member

wadethestealth commented Oct 11, 2019

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
Copy link

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

@tmcdonough
Copy link

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
Copy link

sschuldenzucker commented Jan 27, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants