Signed-off-by: ale <ale@manalejandro.com>
Este commit está contenido en:
ale
2025-10-08 03:59:36 +02:00
padre 63dc85ddae
commit 856bb8e6ca
Se han modificado 3 ficheros con 79 adiciones y 22 borrados

Ver fichero

@@ -167,24 +167,27 @@ export class PythonBridge extends EventEmitter {
/**
* Send command to Python process
*/
private async sendCommand(command: string, args: Record<string, any> = {}): Promise<PythonResponse> {
if (!this.pythonProcess || !this.pythonProcess.stdin) {
throw new Error('Python process not running');
}
const requestId = (++this.requestId).toString();
const commandData = { command, request_id: requestId, ...args };
private async sendCommand(command: string, data?: any): Promise<any> {
return new Promise((resolve, reject) => {
const requestId = Math.random().toString(36).substring(2, 15);
const request = { command, data, requestId };
// Set timeout - longer for target operations
const timeoutDuration = command === 'set_target' ? 10000 : 30000; // 10s for set_target, 30s for others
const timeout = setTimeout(() => {
this.requestQueue.delete(requestId);
reject(new Error(`Python command timeout: ${command}`));
}, this.config.timeout);
}, timeoutDuration);
// Store request with timeout for cleanup
this.requestQueue.set(requestId, { resolve, reject, timeout });
if (!this.pythonProcess) {
reject(new Error('Python process not initialized'));
return;
}
const commandJson = JSON.stringify(commandData) + '\n';
this.pythonProcess!.stdin!.write(commandJson);
this.pythonProcess.stdin?.write(JSON.stringify(request) + '\n');
});
}