Encountered a problem when spawned a process in electron


#1

I have seen some posts about the topic,yes,it run very well when I used electron command in console.But it couldn’t work when I packaged(electron-builder) the electron app,and appeared a problem when I started the app: it was starting create new process constantly,therefore there were a lot of processes in task manager we can see and CPU usage came to 100%. I don’t know how dose this happened, could you help me? please! Here is my test code:

master.js(main):

var childProcess = require('child_process');
let createProc = () => {
  let sp = childProcess.spawn(process.execPath, ['./go.js'], {stdio:'ignore'});
  sp.unref();
  sp.on('error', (err) => {
    console.log('failed to start process',err);
  });
  sp.on('exit',(code, signal) => {
    console.log(`child process exited with code ${code}`);
    createProc();
  });
}

createProc();

go.js:

const {app, BrowserWindow} = require('electron');
let basicWindowParams = {
  show: true,
  autoHideMenuBar:true
};
console.log(process.execPath)
console.log(process.execArgv)
console.log(process.pid)
app.on('ready', () => {
  let win = new BrowserWindow(basicWindowParams);
  win.loadURL('http://www.reddit.com/');
  win.on('did-finish-load', () => {
    win.show();
  });
});

OS: Windows 10

Electron: 1.8.1

Update: I have created a repo for demonstration: https://github.com/xzycn/el_test