[Tutor] pattern matching is too slow (a little OT)

Hugo González Monteverde hugonz-lists at h-lab.net
Fri Aug 12 20:29:57 CEST 2005


Hi again =)

That's exactly why I use "quiet" with MPlayer, because the output is 
simply too much to be parsed, and MPlayer will block waiting for you to 
read the buffer (so it stops playing)

My suggestion is: forget about parsing the huge amounts of output 
MPlayer gives, and use its slave mode instead to know where in the video 
you are)

Vinay Reddy wrote:
> 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.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


More information about the Tutor mailing list