Resuming read after timeout
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- rust
- 領域
- cli, operating-systems
調査の方向性
まず rexpect::exp_eof と drain_read_buffer が使用する reader.try_read のパスを調べ、タイムアウト後に何がバッファに残るのかに注目します。「100ms 後に利用可能なものをすべて読み取る」が返すべき内容と、後続の読み取りで以前の出力が再び返されないようにする方法を定義します。段階的に出力を生成する PTY プロセスで動作を検証してください。
索引モデルが issue の本文から書いたものです。
説明
I have a
pub session: Option<Arc<Mutex<PtySession>>>,
I want to get the existing output of a process after 100ms. This seemed to work at first:
let output = {
let session_mutex = self.session.as_mut().ok_or(anyhow!("No session"))?;
let mut session = session_mutex.lock()?;
match session.exp_eof() {
Ok(output) => output,
Err(e) => {
match e {
rexpect::error::Error::Timeout { got, .. } => got
.replace("`\\n`\n", "\n")
.replace("`\\r`", "\r")
.replace("`^`", "\u{1b}"),
_ => return Err(e.into()),
}
}
}
};
but then I realized that session.exp_eof does not drain the buffer if a timeout is reached, meaning that if I try to read the next chunk, the entire output up to this point is going to be returned yet again. This seems to work:
fn drain_read_buffer(&mut self) -> ZammResult<String> {
let mut output = String::new();
if let Some(session) = self.session.as_mut() {
let reader = &mut session.lock()?.reader;
while let Some(chunk) = reader.try_read() {
output.push(chunk);
}
}
Ok(output)
}
...
let mut output = String::new();
loop {
sleep(Duration::from_millis(100));
let new_output = self.drain_read_buffer()?;
if new_output.is_empty() {
break;
}
output.push_str(&new_output);
}
But I'm wondering, is there a better way to implement "read whatever is available after 100ms" than this?
- 主要言語
- Rust
- スター
- 391
- フォーク
- 69
- 平均マージ
- 1日 34分
- マージ済み PR(30日)
- 2
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rust-cli/rexpect のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 45/100
-
Configurable sleeps オープン
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 25/100
rust-cli/rexpect の issue をすべて見る
似ている issue
-
bug CLI custom-model
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
rust-bitcoin/rust-bitcoin#6930 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
fulcrumgenomics/ferro-hgvs#2251 ·
-
A-allocators A-docs C-enhancement T-libs
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100