Skip to content

Commit fa037be

Browse files
committed
Detach daemon process from parent GUI process
1 parent b8dbb83 commit fa037be

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

packages/gui/src/util/chiaEnvironment.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,27 @@ const getChiaVersion = () => {
7070
const startChiaDaemon = () => {
7171
const script = getScriptPath(PY_DIST_FILE);
7272
const processOptions = {};
73-
// processOptions.detached = true;
74-
// processOptions.stdio = "ignore";
73+
// We want to detach child daemon process from parent GUI process.
74+
// You may think `detached: true` will do but it shows blank terminal on Windows.
75+
// In order to hide the blank terminal while detaching child process,
76+
// {detached: false, windowsHide: false, shell: true} works which is exact opposite of what we expect
77+
// Please see the comment below for more details.
78+
// https://github.com/nodejs/node/issues/21825#issuecomment-503766781
79+
processOptions.detached = false;
80+
processOptions.stdio = 'ignore';
81+
processOptions.windowsHide = false;
82+
processOptions.shell = true;
7583
pyProc = null;
7684
if (guessPackaged()) {
7785
try {
7886
console.info('Running python executable: ');
79-
const Process = childProcess.spawn;
80-
pyProc = new Process(script, ['--wait-for-unlock'], processOptions);
87+
if (processOptions.stdio === 'ignore') {
88+
const subProcess = childProcess.spawn(script, ['--wait-for-unlock'], processOptions);
89+
subProcess.unref();
90+
} else {
91+
const Process = childProcess.spawn;
92+
pyProc = new Process(script, ['--wait-for-unlock'], processOptions);
93+
}
8194
} catch (e) {
8295
console.info('Running python executable: Error: ');
8396
console.info(`Script ${script}`);
@@ -86,10 +99,15 @@ const startChiaDaemon = () => {
8699
console.info('Running python script');
87100
console.info(`Script ${script}`);
88101

89-
const Process = childProcess.spawn;
90-
pyProc = new Process('python', [script, '--wait-for-unlock'], processOptions);
102+
if (processOptions.stdio === 'ignore') {
103+
const subProcess = childProcess.spawn('python', [script, '--wait-for-unlock'], processOptions);
104+
subProcess.unref();
105+
} else {
106+
const Process = childProcess.spawn;
107+
pyProc = new Process('python', [script, '--wait-for-unlock'], processOptions);
108+
}
91109
}
92-
if (pyProc != null) {
110+
if (pyProc != null && processOptions.stdio !== 'ignore') {
93111
pyProc.stdout.setEncoding('utf8');
94112

95113
pyProc.stdout.on('data', (data) => {

0 commit comments

Comments
 (0)