Re: running python script with [command] outputs info only when script exits
Roman Haefeli <[email protected]>
| Newsgroups | gmane.comp.multimedia.puredata.general |
|---|---|
| Message-ID | <[email protected]> |
It seems that Python's "print" buffers its output per default. The
issue you experience seems not specific to [command], but happens also
when you pipe the output to some other command, like in:
./counter.py | grep 2
You will see the '2' only appear when the whole script has finished
running.
You can tell print to immediately flush the current buffer:
print(i, flush=True)
cheers,
Roman
On Tue, 2024-12-10 at 12:02 +0200, Alexandros Drymonitis wrote:
> Is it possible to run a Python script with [command] that runs a
> `while
> True` loop and have it print data to the middle outlet of [command]
> continuously? I can't see how to make this work. As a test, I wrote
> the
> script below and tested it:
>
> ```
> from time import sleep
>
> for i in range(10):
> print(i)
> sleep(1)
> ```
>
> [command] will output 10 numbers together when the script exits. Is
> it
> possible to get the incrementing variable i printed every second?
>
>
> ---
> [email protected] - the Pure Data mailinglist
> https://lists.iem.at/hyperkitty/list/[email protected]/message/ZSZSQRZCLC5QQINZ2YKJXPPCNXB2EVH5/
>
> To unsubscribe send an email to [email protected] mailing
> list
> UNSUBSCRIBE and account-management -> https://lists.iem.at/
---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/JKC2GRQC5GMJ44K6IAWOHVR3GGS3VJFS/
To unsubscribe send an email to [email protected] mailing list
UNSUBSCRIBE and account-management -> https://lists.iem.at/
signature.asc
(application/pgp-signature, 512 B)
-----BEGIN PGP SIGNATURE----- iQFHBAABCgAxFiEEZhiayanamWnbdJ1ZfR/MvBcPEc0FAmdYGHITHHJlZHV6ZW50 QGdtYWlsLmNvbQAKCRB9H8y8Fw8RzUp9B/0XQZU+pFcGkwTVq9uNDjWadBgsyusZ 0wj3vh7hcHkrZmjMxjc73zTOxT8j5YVoFpb332U6DtB7dVAOwq+Jp0Nyoehf2142 0b5sn9ZUpmDE6qAhqAov2c5vpO7HRxySGVa0hKj17fNLOn/x+LifNB/oUdEbibhP ezPNvNbWCNPvU5hYLjcja0G9qkFkou7gmvItZMRtV2IH+8glWITY2cQcPZTDZvbd t9eqiG2YD+nIFhXhV46126XXEQol8mNZwWtBxX+xyo9f+nkKzBRwpdC8Ygoyxtlg SNlnMZrNopEOovO7LD8S0Ind88d6hKassFXaLiMrX72gOXi2dBncsmE1 =ErQ2 -----END PGP SIGNATURE-----