(file, fcn, args, options, callback)
| 125 | } |
| 126 | |
| 127 | call(file, fcn, args, options, callback) { |
| 128 | debug(`enter call(), state: ${String(this.state)}, uuid: ${this.uuid}`); |
| 129 | if (!this._checkState([CREATED, WAITING])) return callback(new Error('invalid PythonCaller state')); |
| 130 | |
| 131 | if (this.state == CREATED) { |
| 132 | this._startChild(); |
| 133 | } |
| 134 | |
| 135 | const localOptions = _.defaults(options, { |
| 136 | cwd: __dirname, |
| 137 | paths: [], |
| 138 | timeout: 20000, // FIXME: this number (equivalent to 20 seconds) should not have to be this high |
| 139 | }); |
| 140 | const callData = { |
| 141 | file, fcn, args, |
| 142 | cwd: localOptions.cwd, |
| 143 | paths: localOptions.paths, |
| 144 | }; |
| 145 | const callDataString = JSON.stringify(callData); |
| 146 | this.callback = callback; |
| 147 | this.timeoutID = setTimeout(this._timeout.bind(this), localOptions.timeout); |
| 148 | |
| 149 | this.outputStdout = ''; |
| 150 | this.outputStderr = ''; |
| 151 | this.outputBoth = ''; |
| 152 | this.outputData = ''; |
| 153 | |
| 154 | this.lastCallData = callData; |
| 155 | |
| 156 | this.child.stdin.write(callDataString); |
| 157 | this.child.stdin.write('\n'); |
| 158 | |
| 159 | this.state = IN_CALL; |
| 160 | this._checkState(); |
| 161 | debug(`exit call(), state: ${String(this.state)}, uuid: ${this.uuid}`); |
| 162 | } |
| 163 | |
| 164 | /* |
| 165 | * @param {function} callback - A callback(err, success) function. If 'success' is false then this PythonCaller should be discarded and a new one created by the parent. |
no test coverage detected