| 100 | }, |
| 101 | |
| 102 | returnPythonCaller(pc, callback) { |
| 103 | debug('returnPythonCaller()'); |
| 104 | load.endJob('python_worker_active', pc.uuid); |
| 105 | if (!config.useWorkers) { |
| 106 | pc.done(); |
| 107 | callback(null); |
| 108 | return; |
| 109 | } |
| 110 | callback(null); |
| 111 | pc.restart((err, success) => { |
| 112 | let needsFullRestart = false; |
| 113 | if (err) { |
| 114 | debug('returnPythonCaller(): restart returned error: ${err}'); |
| 115 | logger.error(`Error restarting pythonCaller: ${err}`); |
| 116 | needsFullRestart = true; |
| 117 | } else { |
| 118 | if (!success) { |
| 119 | debug('returnPythonCaller(): restart requested a full restart'); |
| 120 | // no error logged here, everything is still ok |
| 121 | needsFullRestart = true; |
| 122 | } |
| 123 | } |
| 124 | if (needsFullRestart) { |
| 125 | const i = pc.number; |
| 126 | pc.done(); |
| 127 | debug('returnPythonCaller(): making new pythonCaller'); |
| 128 | pc = new codeCaller.PythonCaller(); |
| 129 | pc.number = i; |
| 130 | pythonCallers[i] = pc; |
| 131 | } |
| 132 | // by this point either the restart succeeded or we have a brand new PythonCaller |
| 133 | if (waitingCallbacks.length > 0) { |
| 134 | debug('returnPythonCaller(): passing to a waiting callback'); |
| 135 | const cb = waitingCallbacks[0]; |
| 136 | waitingCallbacks = waitingCallbacks.slice(1); |
| 137 | load.endJob('python_callback_waiting', cb.__load_uuid); |
| 138 | load.startJob('python_worker_active', pc.uuid); |
| 139 | cb(null, pc); |
| 140 | } else { |
| 141 | debug('returnPythonCaller(): pushing back onto availablePythonCallers'); |
| 142 | load.startJob('python_worker_idle', pc.uuid); |
| 143 | availablePythonCallers.push(pc); |
| 144 | } |
| 145 | }); |
| 146 | }, |
| 147 | |
| 148 | _warmUpWorkers() { |
| 149 | debug('_warmUpWorkers()'); |