mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-29 12:11:09 +00:00
much improved support for background processes, avoiding termination (via SIGPIPE) or eventual blocking (e.g. due to filled OS buffers) (#586)
This commit is contained in:
parent
00805cb2cd
commit
0d99398689
2 changed files with 35 additions and 30 deletions
|
|
@ -120,13 +120,19 @@ export const useShellCommandProcessor = (
|
|||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
|
||||
let exited = false;
|
||||
let output = '';
|
||||
const handleOutput = (data: string) => {
|
||||
output += data;
|
||||
setPendingHistoryItem({
|
||||
type: 'info',
|
||||
text: output,
|
||||
});
|
||||
// continue to consume post-exit for background processes
|
||||
// removing listeners can overflow OS buffer and block subprocesses
|
||||
// destroying (e.g. child.stdout.destroy()) can terminate subprocesses via SIGPIPE
|
||||
if (!exited) {
|
||||
output += data;
|
||||
setPendingHistoryItem({
|
||||
type: 'info',
|
||||
text: output,
|
||||
});
|
||||
}
|
||||
};
|
||||
child.stdout.on('data', handleOutput);
|
||||
child.stderr.on('data', handleOutput);
|
||||
|
|
@ -136,7 +142,8 @@ export const useShellCommandProcessor = (
|
|||
error = err;
|
||||
});
|
||||
|
||||
child.on('close', (code, signal) => {
|
||||
child.on('exit', (code, signal) => {
|
||||
exited = true;
|
||||
setPendingHistoryItem(null);
|
||||
output = output.trim() || '(Command produced no output)';
|
||||
if (error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue