Python io.BytesIO binary stream as {out,err}_stream container
还没有人认领这个 Issue。
评估
调研方向
Start with invoke/runners.py, especially handle_stdout and write_our_output, and the run wrapper in invoke/util.py. Determine how out_stream and err_stream handle binary file-like objects in synchronous and asynchronous execution; done means BytesIO receives real-time output without the reported TypeError or requiring filesystem storage.
由索引模型根据 Issue 内容生成。
描述
Hi,
I'm trying to capture and process in real time the output of a command started with run in asynchronous mode, with the out_stream option using an in-memory buffer. So I've used the built-in io library with BytesIO class: is this class supported in your Invoke implementation?
I post the following code example:
import io
import time
from invoke import run
out = io.BytesIO()
run('ls -la && sleep 2 && ls -la', warn=True, pty=True, out_stream=out, asynchronous=True)
time.sleep(1)
while True:
myline=out.readline()
print(myline)
time.sleep(1)
if not myline:
out.close()
break
If you run this code, as you can see, it won't print any binary data despite readline() method is supported by BytesIO class. It seems run method is not writing in the out binary (buffer) object. Furthermore if you put asynchronous to False the script exits with this error:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/invoke/util.py", line 237, in run
super(ExceptionHandlingThread, self).run()
File "/usr/lib/python3.9/threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.9/dist-packages/invoke/runners.py", line 756, in handle_stdout
self._handle_output(
File "/usr/local/lib/python3.9/dist-packages/invoke/runners.py", line 730, in _handle_output
self.write_our_output(stream=output, string=data)
File "/usr/local/lib/python3.9/dist-packages/invoke/runners.py", line 718, in write_our_output
stream.write(encode_output(string, self.encoding))
TypeError: a bytes-like object is required, not 'str'
AFAIK io.BytesIO() is not a 'str' object, it's a binary stream using an in-memory bytes buffer.
Is it possible to use a BytesIO type (for binary data) as a buffer container of {out,err}_stream? If not, is it possible to implement it in Invoke, in order to process the output stream in real time (not when the command, that is very long in my project, has finished) without using filesystem (file-like) objects?
Thank you in advance for your help!
Roberto
- 主要语言
- Python
- 星标
- 4.8k
- 派生
- 417
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pyinvoke/invoke 的其他 Issue
-
[Security] Shell injection via Context.cd() path argument — metacharacters not escaped (CWE-78)可能已有人在做 @HarshRajSinghania 于 22 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
-
Runner.respond uses join leading to slowness可能已有人在做 @aryansk 于 59 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
-
Long tasks name make `invoke --list | grep a` crash with "invalid width"可能已有人在做 @cyphercodes 于 134 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 2/5 1-3 小时 新手友好度 70/100
-
Type hints of config do not accept other values than str可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 64/100
相似的 Issue
-
[Bug]: Streamed /v1/chat/completions sends unredacted agent error text (keys) in the final chunk可能已有人在做 @rodricksz4h5 今天认领。 未关闭area/streaming comp/gateway P2 type/security
难度 2/5 1-3 小时 新手友好度 78/100
NousResearch/hermes-agent#138245 ·
维护者通常 1 天内回复
-
[oblt-aw][autodoc] Update user onboarding guide for mandatory trigger CODEOWNERS step可能已有人在做 @github-actions 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复
-
correction metadata
难度 2/5 1 小时以内 新手友好度 68/100
acl-org/acl-anthology#10378 · 1 条评论 ·
维护者通常 1 天内回复
-
cloudtrail_multi_region_enabled_logging_management_events fails when the advanced event selector has a custom name可能已有人在做 @12YYCCYY16 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
prowler-cloud/prowler#13033 ·
维护者通常 1 天内回复
-
enhancement
难度 1/5 1-3 小时 新手友好度 88/100
graygarbage/HermesKey#23 ·