[Tutor] pattern matching is too slow

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


hi Vinay,

Reading through other posts, looks like you got somewhare with the 
nonblocking IO. Can you comment on what you did to get it working? The 
whole fcntl thing?

Thanks,

Hugo

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