Created
July 11, 2013 13:35
-
-
Save kghose/5975486 to your computer and use it in GitHub Desktop.
Demonstration of the limitation of Python's subprocess.PIPE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from subprocess import Popen, PIPE | |
import argparse, time | |
def execute(n): | |
p = Popen(['python', 'test.py', '-n', str(n)], stdin=PIPE, stdout=PIPE, stderr=PIPE) | |
p.wait() | |
return p.stdout.read().splitlines() | |
def execute_long(n): | |
with open('query.txt','w') as stdout: | |
p = Popen(['python', 'test.py', '-n', str(n)], stdin=PIPE, stdout=stdout, stderr=PIPE) | |
p.wait() | |
with open('query.txt','r') as stdout: | |
return stdout.read().splitlines() | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-n', type=int) | |
args = parser.parse_args() | |
if args.n is not None: | |
print '0'*args.n | |
else: | |
for n in [10,100,1000,10000,12000,16000,32000,64000,128000]: | |
t0 = time.clock() | |
execute_long(n) | |
print n, time.clock() - t0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment