Question about unreasonable slowness

Éric Daigneault daigno at
Thu Nov 16 22:46:05 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?

Tried it on my comp (battered up winXP laptop on it's last breath) with the following change...

  (shellIn, shellOut) = os.popen4("cmd ")

and the performance with or without the inserted for loop is roughly equivalent albeit a /bit/ slower with  the for loop is  but I would need timers really make it stand out (under 1 second difference).

All in all, rough estimation is that both take more or less 4 seconds to complete which is what I would expect knowing my system...

Anyways, is what I got...

Hope it helps somehow

Éric :D.

More information about the Python-list mailing list