<div dir="ltr"><div>On Wed, May 3, 2017 at 5:34 AM, Moritz Lennert <<a href="mailto:mlennert@club.worldonline.be">mlennert@club.worldonline.be</a>> wrote:<br>><br>> On 02/05/17 15:53, Vaclav Petras wrote:<br>>> I'm using pipe_command() which is just convenience function setting<br>>> stdout=PIPE. Similarly feed_command() is just setting stdin=PIPE which<br>>> I'm not using because I'm feeding the stdout of the other process<br>>> directly (stdin=first_process.stdout). What I don't understand,<br>>> regardless of using stdin=PIPE or stdin=first_process.stdout for the<br>>> second process, is what should be next.<br>><br>> Do you really need the in_process.communicate() ? Here's what I used<br>> in a local script and it works, without communicate(). Then again,<br>> I don't think the data flowing through this pipe ever exceeded available memory.<br>><br>>         pin = gscript.pipe_command('v.db.select',<br>>                                    map = firms_map,<br>> ...<br>>         total_turnover_map = 'turnover_%s' % nace2<br>>         p = gscript.start_command('<a href="http://r.in.xyz">r.in.xyz</a>',<br>>                                   input_='-',<br>>                                   stdin=pin.stdout,<br>> ...<br>>         if p.wait() is not 0:<br>>             gscript.fatal("Error in <a href="http://r.in.xyz">r.in.xyz</a> with nace %s" % nace2)<br><br></div>The Popen.wait() documentation [1] says: "Warning: This will deadlock when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data. Use communicate() to avoid that."<br><div><div><br>And since I'm using stdout=PIPE (pipe_command()), I use communicate(). What troubles me is that Popen.communicate(input=None) documentation [2] says: "Note: The data read is buffered in memory, so do not use this method if the data size is large or unlimited."<br><br></div><div>It says "data read", so it probably talks about stdout=PIPE when communicate() does not return None(s) but data (stdout=PIPE and communicate with the same process), i.e. it doesn't apply to this case and I don't have to be troubled. As for the wait(), I think that it may work (works most of the time), it is just not guaranteed to work with large data and it depends on how smart the OS will be.<br></div><div><br></div><div>Vaclav<br></div><div><br>[1] <a href="https://docs.python.org/2/library/subprocess.html#subprocess.Popen.wait">https://docs.python.org/2/library/subprocess.html#subprocess.Popen.wait</a><br>[2] <a href="https://docs.python.org/2/library/subprocess.html#subprocess.Popen.communicate">https://docs.python.org/2/library/subprocess.html#subprocess.Popen.communicate</a><br><br></div></div></div>