Question about unreasonable slowness

allenjo5 at allenjo5 at
Thu Nov 16 21:45:18 CET 2006

[ Warning: I'm new to Python.  Don't know it at all really yet, but had
to examine some 3rd party code because of performance problems with it.

Here's a code snippet:

i = 0
while (i < 20):
  i = i + 1
  (shellIn, shellOut) = os.popen4("/bin/sh -c ':'")  # for testing, the
spawned shell does nothing
  print 'next'
#  for line in shellOut:
#       print line

On my system (AIX 5.1 if it matters, with Python 2.4.3), this simple
loop spawning 20 subshells takes .75 sec.  Ok, that's reasonable.  Now,
if I uncomment the two commented lines, which loop over the empty
shellOut array, the progam now takes 11 secs.   That slowdown seems
very hard to believe.  Why should it slow down so much?


More information about the Python-list mailing list