Skip to content

Quit gracefully when Ctrl-C is pressed in console #5273

@elisee

Description

@elisee
  • Electron version: v0.37.7
  • Operating system: Windows 10 (64-bit)

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 with electron index.js:

setTimeout(() => { /* Just to keep process running */ }, 1000000);

process.on("SIGINT", () => {
  console.log("Caught SIGINT. Exiting in 5 seconds.");

  setTimeout(() => {
    console.log("This should appear in the Electron console but the process will be long killed.");
    process.exit(0);
  }, 5000);
});

Prints for instance Caug or Caught S on my PC right before exiting and the rest of the function doesn't get executed. I believe that's not intended behavior.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions