[Tutor] pattern matching is too slow

Vinay Reddy vinayvinay at gmail.com
Fri Aug 12 09:11:25 CEST 2005


Hi,
I am writing a front-end for an application (mplayer). I used the
popen2 call to open pipes for bi-directional communication.

I set the output pipe from the application to non-blocking mode using:
fcntl.fcntl(self.mplayerOut, fcntl.F_SETFL, os.O_NONBLOCK)

The problem is that it takes about 10 seconds just to parse through
the inital dump of mplayer (during which mplayer stops playing).

I'm using the following code to read from 'mplayerOut':

while True:
 try:
    temp = self.mplayerOut.readline()
       print temp
       if re.compile("^A:").search(temp):
          print "abc"
 except StandardError:
    break

If the remove the re.compile() statement, then the output is
instantaneous and there is no delay. Why is pattern matching so slow?
It's increasing the time almost by 1 second per line of output. How
can I get it to run faster?

Any help will be appreciated.

Regards,
Vinay Reddy

PS: This is my first python program.


More information about the Tutor mailing list