Python io.BytesIO binary stream as {out,err}_stream container
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Python
- Stelle
- 4.8k
- Fork
- 412
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pyinvoke/invoke
-
[Security] Shell injection via Context.cd() path argument — metacharacters not escaped (CWE-78) Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
Tutte le issue di pyinvoke/invoke
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
xinnan-tech/xiaozhi-fde-talk#263 ·
-
rules
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
huggingface/Repo2RLEnv#163 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
huggingface/sentence-transformers#4074 ·
-
comp/dashboard invalid P3
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
NousResearch/hermes-agent#121143 ·