@@ -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');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Referencia en una nueva incidencia
Block a user