lopmay.blogg.se

Get data return from python subprocess call
Get data return from python subprocess call





get data return from python subprocess call

P = subprocess.Popen((, ">", diz+"/points.xml"])Īs stated in the documentation, wait can deadlock, so communicate is advisable. If you want to do things while it is executing or feed things into stdin, you can use communicate after the popen call.

get data return from python subprocess call

If you want the commands to block and not do anything while it is executing, you can just use subprocess.call. The data read is buffered in memory, so do not use this method if the data size is large or unlimited.ġ) If you want to block directly to the end of subroutine call after calling :ĭepending on how you want to work your script you have two options. Ĭonclusion : If you use subprocess.Popen, Don't use Popen.wait(), While using municate() To wait for the external program execution to finish. And if you want to get the program return value, You can call municate() Then take Popen.returncode Value. This method puts the output in memory, Not in the pipe, So the upper limit is related to the memory size, Generally no problem. How to avoid deadlock ? Recommended in official documents municate(). You can see the right start and end Output And then the test is better than 64KB In many cases, In this case, only start, In other words, the program execution is stuck in p.wait() On, Program deadlock. Use dd It's just that 64KB Standard output of, from subprocess.Popen call, And then use wait() wait for dd End of call. P = subprocess.Popen(args=cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)įirst, the test output is 64KB The size of the situation.

get data return from python subprocess call

Ulimit -a What you see pipe size yes 4KB, That's just the size of each page, The inquiry found that linux default pipe size yes 64KB.Ĭmd = 'dd if=/dev/urandom bs=1 count=%d 2>/dev/null' % size In short, it is, Use subprocess Modular Popen Call the external program, If stdout or stderr Parameter is pipe, And the program output exceeds that of the operating system pipe size when, If you use Popen.wait() Method wait for the program to end to get the return value, Meeting Lead to a deadlock, Where is the program card wait() Call up. In order to make this problem clear, Search for some information, come and have a look :Ī problem we have today. google Find out wait Deadlock is possible. The reason why I'm stuck with this is that I find that I'm calling Popen Of wait Method, the program never returns.







Get data return from python subprocess call