-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Quit gracefully when Ctrl-C is pressed in console #5273
Comments
For GUI programs it is very unreliable to handle quitting with SIGINT signal, in Electron the SIGINT signal is hijacked to call |
Neither setTimeout(() => { /* Just to keep process running */ }, 1000000);
const electron = require("electron");
electron.app.on("before-quit", (event) => {
// This is never called! Replacing before-quit with will-quit doesn't help.
console.log("Caught before-quit. Exiting in 5 seconds.");
event.preventDefault();
setTimeout(() => { process.exit(0); }, 5000);
}); |
There is no |
Node.js catches Maybe there's a way that Electron can check for a registered Relevant section from the Node.js
|
Ah I see, so in Node they use However we should have at least a decent way to handle a situation like this, we can probably follow the behavior on OS X that calls |
Can confirm that process.on('SIGINT') is called running as node (6.2.0), not as electron (1.2.3), on Ctrl-C I'm doing this on command line, there is no UI but as you say the app may be run as GUI I'd very much Electron to work same way as node. |
Run this in Windows cmd prompt and behold the very weird behaviour
OS X 10.11 - do Ctrl C
|
After looking into this, I'm afraid this is a limitation of Window. Since Electron is an GUI app, there is no way to catch the Ctrl-C event from Windows, even when we setup a handle with So I'm closing this as won't fix. |
I've found a weird thing: when I press |
How could I distinguish whether the |
发现app.quit会调用win.close 但登录后close开始不起效 需要win.destroy 十分奇怪 electron/electron#5273
Sry for necroposting, but ctrl-c doesn't seem to be caught in ubuntu as well (using xfce terminal to be specific), should I create a new issue? On a side note - I'm also unable to catch anything and do a graceful shutdown on ubuntu reboot... this exit handling feels like a mess, to be honest. |
I am on Electron 30.0.9 on macOS Sonoma and running Electron via the command line and then killing it using Ctrl+C prints this line:
I would like to get rid of this line. Has anyone found a solution that works for macOS? Edit: this ended up working for me. Must be in the electron.app.on('ready', async () => {
// Prevent "exited with signal SIGINT" to be printed to the console
// Note that this must be in the `ready` event handler
process.on("SIGINT", () => process.exit(0));
// … |
FWIW, as of 30.0.x, when I kill my electron app from a shell using ctrl-c (in MS Windows) it leaves behind zombie process - two renderers and a crashpad-handler (of which the crashpad-handler chews up CPU cycles). I don't have a simple replicator yet but it does seem like something must have changed with signal handling in 30 so posting here in case anyone else stumbles on a solution or can replicate. |
Hi,
In Node.js, listening for the
SIGINT
event cancels its default behavior of exiting the process.In Electron, the
SIGINT
event handler is called but the process still exits ASAP so the event handler will be interrupted randomly while it's doing its thing. For instance, running the following withelectron index.js
:Prints for instance
Caug
orCaught S
on my PC right before exiting and the rest of the function doesn't get executed. I believe that's not intended behavior.The text was updated successfully, but these errors were encountered: