()
| 219 | } |
| 220 | |
| 221 | _startChild() { |
| 222 | debug(`enter _startChild(), state: ${String(this.state)}, uuid: ${this.uuid}`); |
| 223 | this._checkState([CREATED]); |
| 224 | load.startJob('python', this.uuid); |
| 225 | activeCallers[this.uuid] = this; |
| 226 | |
| 227 | const cmd = 'python3'; |
| 228 | var pythonTrampoline; |
| 229 | if (config.useWorkers) { |
| 230 | pythonTrampoline = path.join(__dirname, 'python-caller-trampoline.py'); |
| 231 | } else { |
| 232 | pythonTrampoline = path.join(__dirname, 'python-caller-trampoline-no-fork.py'); |
| 233 | } |
| 234 | const args = ['-B', pythonTrampoline]; |
| 235 | const env = _.clone(process.env); |
| 236 | // PYTHONIOENCODING might not be needed once we switch to Python 3.7 |
| 237 | // https://www.python.org/dev/peps/pep-0538/ |
| 238 | // https://www.python.org/dev/peps/pep-0540/ |
| 239 | env.PYTHONIOENCODING = 'utf-8'; |
| 240 | const options = { |
| 241 | cwd: __dirname, |
| 242 | stdio: ['pipe', 'pipe', 'pipe', 'pipe'], // stdin, stdout, stderr, and an extra one for data |
| 243 | env, |
| 244 | }; |
| 245 | this.child = child_process.spawn(cmd, args, options); |
| 246 | debug(`started child pid ${this.child.pid}, uuid: ${this.uuid}`); |
| 247 | |
| 248 | this.child.stderr.setEncoding('utf8'); |
| 249 | this.child.stdout.setEncoding('utf8'); |
| 250 | this.child.stdio[3].setEncoding('utf8'); |
| 251 | |
| 252 | this.child.stderr.on('data', this._handleStderrData.bind(this)); |
| 253 | this.child.stdout.on('data', this._handleStdoutData.bind(this)); |
| 254 | this.child.stdio[3].on('data', this._handleStdio3Data.bind(this)); |
| 255 | |
| 256 | this.child.on('exit', this._handleChildExit.bind(this)); |
| 257 | this.child.on('error', this._handleChildError.bind(this)); |
| 258 | |
| 259 | this.state = WAITING; |
| 260 | this._checkState(); |
| 261 | debug(`exit _startChild(), state: ${String(this.state)}, uuid: ${this.uuid}`); |
| 262 | } |
| 263 | |
| 264 | _handleStderrData(data) { |
| 265 | debug(`enter _handleStderrData(), state: ${String(this.state)}, uuid: ${this.uuid}`); |
no test coverage detected