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?
hello,
it should work if you start your script in a termminal and pipe it to pdsend :
./test.py | pdsend 6789 localhost udp
use a netreceive object to get the script result.
cheers c
Le 10/12/2024 à 11:02, Alexandros Drymonitis a écrit :
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?
pd-list@lists.iem.at - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/pd-list@lists.iem.at/message/ZSZSQRZCLC...
To unsubscribe send an email to pd-list-leave@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/
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?
pd-list@lists.iem.at - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/pd-list@lists.iem.at/message/ZSZSQRZCLC...
To unsubscribe send an email to pd-list-leave@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/
On 12/10/24 12:31, Roman Haefeli wrote:
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)
That did the trick, thanks!
On 10/12/2024 10:31, Roman Haefeli wrote:
It seems that Python's "print" buffers its output per default.
You can also disable output buffering entirely in a few different ways if you don't want to explicitly put flush in every print statement:
-u
command line switchPYTHONUNBUFFERED
env varsys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
https://stackoverflow.com/questions/107705/disable-output-buffering
Cheers,
Chris.