| 76 | }, |
| 77 | |
| 78 | getPythonCaller(callback) { |
| 79 | debug('getPythonCaller()'); |
| 80 | if (!config.useWorkers) { |
| 81 | const pc = new codeCaller.PythonCaller(); |
| 82 | load.startJob('python_worker_active', pc.uuid); |
| 83 | callback(null, pc); |
| 84 | return; |
| 85 | } |
| 86 | if (pythonCallers.length == 0) return callback(new Error('no PythonCallers initialized')); |
| 87 | if (availablePythonCallers.length > 0) { |
| 88 | const pc = availablePythonCallers[0]; |
| 89 | availablePythonCallers = availablePythonCallers.slice(1); |
| 90 | load.endJob('python_worker_idle', pc.uuid); |
| 91 | debug(`getPythonCaller(): got ${pc.number}`); |
| 92 | load.startJob('python_worker_active', pc.uuid); |
| 93 | callback(null, pc); |
| 94 | } else { |
| 95 | debug(`getPythonCaller(): adding to waitingCallbacks`); |
| 96 | callback.__load_uuid = uuidv4(); |
| 97 | load.startJob('python_callback_waiting', callback.__load_uuid); |
| 98 | waitingCallbacks.push(callback); |
| 99 | } |
| 100 | }, |
| 101 | |
| 102 | returnPythonCaller(pc, callback) { |
| 103 | debug('returnPythonCaller()'); |