New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
default subprocess.Popen buffer size #48444
Comments
I noticed a colleague at work today checked in a change to his code to
These times are on my Mac laptop, all writing to the local disk. It seems His original test used time.clock() as the timer. I changed to time.time() Skip |
Hi Skip, I find different measurements om Windows/XP: I copied the script and ran Plappert@action-time /cygdrive/e/tmp $ python ./timing.py # 2.5.2 in other words: identical or subprocess.Popen even faster. and it is getting even better with Python2.6: Plappert@action-time /cygdrive/e/tmp $ python26 timing.py # 2.6 So could that be a Mac OS issue? |
Good question. I don't think it's MacOSX-specific. The original problem |
The subprocess module does different things depending on whether the If this is correct, then we should see poor performance on Linux also. |
Good suggestion Sameer. I tried it out with Python 2.5 on a Linux host S |
cygwin Python 2.5.1 (similar) linux python 2.4.2 (similar) linux python3K (both awful) |
I don't expect Python3 to be all that great io performance-wise yet. % python3.0 popentest.py |
Here are my figures from a different processor on Linux (Ubuntu): wplapper@lin-wpl: |
Yes, I can confirm that the performance is lousy on Solaris. Solaris-9/Python 2.5.1: Solaris-9/Python 2.6: Solaris-10/Python 2.4.4: Solaris-10/Python 2.6: All machines are idendital in processor speed: v240. |
Hi is the dramatic difference on Solaris-10 / Python2.6: I dtraced the popentest.py and counted syscalls: with os_popen: read = 243
with process:Popen read = 589018 That explains a lot! The rest of the system calls are similir in count and appearance. |
s/Hi is/Hi, here is/ :) |
The created testfile size is 588890 bytes, which implies that I think I have got it: Lib/subprocess.py should have a default bufsize See also Modules/posixmodule.c. |
Using a nonzero bufsize parameter makes all the difference in the world: Using the default (bufsize=0 ==> unbuffered):
Creating the Popen object with bufsize=8192:
Creating the Popen object with bufsize=1 (==> line buffered):
Maybe the default for that parameter shouldn't be zero? Skip |
In fact, looking at posix_popen in posixmodule.c it appears the default Even if the default bufsize value for subprocess.Popen is not changed its
pipe = os.popen(cmd, mode='r', [bufsize])
==>
pipe = Popen(cmd, shell=True, bufsize=bufsize, stdout=PIPE).stdout
|
I've been thinking about it, and I think even though it would be a slight S |
On the other hand, we will silently break all those applications which bufsize, if given, has the same meaning as the corresponding argument to |
About Python3, os.popen() is more than two times faster (0.20 sec vs |
Summary of unchanged Python (2.4 .. 2.7):
With a different buffer size:
Notes:
|
If anything for 2.6 lets just highlight this in the docs and mention We can consider changing the default for 2.7/3.1. 3.x having poor performance is pretty much another issue entirely of its |
Victor> About Python3, os.popen() is more than two times faster (0.20 This is a known issue. The default for bufsize in os.popen is -1 (fully Skip |
Wrong, it's not related to the buffer size. With Python3 trunk on Linux, os.popen time is ~0.10 sec whereas
You get the same speed (than os.popen) using TextIOWrapper() adapter: WTF? Unicode is *FASTER* than raw bytes? |
I just wanna say that buffering can be a problem when writing, but not |
The strange performance between bytes/text |
Can someone check if this still applies to Python 3.1/3.2? |
Looks good to me: tmp% python3.1 popentest.py
|
Tested it on mac OSX (Snow leopard) Shashwat-Anands-MacBook-Pro:Desktop l0nwlf$ python2.5 popentest.py Python 2.5.4s os.popen was faster than subprocess.Popen, the same being the case with Python 2.6.1 I do not think it is a mac issue. |
The subprocess doc now has a note about buffering and performance issues, closing. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: