![]() ![]() The following gets around the buffering issues by outputting to a temporary file and allows you to parse the data coming from rsync without connecting to a pty. I've noticed that there is no mention of using a temporary file as intermediate. If that happens with the python code above and not with rsync, that means rsync itself is buffering output, so you are out of luck.Ī solution would be to connect direct to a pty, using something like pexpect. To test for that, try running this instead: cmd = Īnd create a test_out.py file with the contents: import sysĮxecuting that subprocess should give you "Hello" and wait 10 seconds before giving "World". This is the default behavior - when connected to a pipe, programs must explicitly flush stdout for realtime results, otherwise standard C library will buffer. ![]() That said, it is probable that rsync buffers its output when it detects that it is connected to a pipe instead of a terminal. Don't redirect stdin when you're not writing to it.Įxample: import subprocess, time, os, sysĬmd = įor line in iter(p.stdout.readline, b''):.Don't redirect stderr to a PIPE when you're not reading it.So you pass a list to Popen to call subprocesses, not a string. sys.argv in python is a list, and so is argv in C. When calling processes, arguments are passed around as lists.It needlessly invokes an extra shell process to call your program. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |