[Tutor] pattern matching is too slow
Hugo González Monteverde
hugonz-lists at h-lab.net
Fri Aug 12 20:35:18 CEST 2005
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?
Vinay Reddy wrote:
> 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:
> temp = self.mplayerOut.readline()
> print temp
> if re.compile("^A:").search(temp):
> print "abc"
> except StandardError:
> 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.
> Vinay Reddy
> PS: This is my first python program.
> Tutor maillist - Tutor at python.org
More information about the Tutor