[Tutor] How to get messages from stderr

Michael Lange klappnase@8ung.at
Wed Aug 6 18:10:05 EDT 2003


On Thu, 31 Jul 2003 10:05:29 -0700
"Jeff Shannon" <jeff@ccvcorp.com> wrote:

> I believe that your problem may be with using read(), with no arguments. 
>  By default, read() will return everything up to end-of-file.  For a 
> pipe, EOF doesn't occur until the pipe is closed.  Therefore, 
> self.ppp.read() will block until the pipe is closed, i.e. the command 
> stops running.
> 
> Try calling read() with an argument multiple times, and assembling the 
> results yourself.  In one of my own programs, I needed to supply input 
> to an external command, and determined that that command would output 
> exactly 18 bytes of data before waiting for input, so I used this code:
> 
>     def _runcommand(self, command):
>         print command
>         i, o = os.popen4(command)
>         print o.read(18)
>         i.write(self.paramstring)
>         i.write('\n')
>         i.flush()
>         result = o.readlines()
>         return result
> 
> I couldn't just use read() or readlines(), because those calls would 
> hang waiting for EOF or EOL respectively, neither of which would happen 
> at the point I was interested in.
> 
Thanks for that hint!
Now I do get the messages from stderr, but somehow the child process gets extremely slowed down.
What have I done wrong here?


	def normalize(self, ev):
		'''Starts "normalize -m" on all selected files.'''
		if self.tracklist.listbox.size() == 0:
			tkMessageBox.showerror(message=nofilesmsg)
		elif self.tracklist.listbox.size() == 1:
			tkMessageBox.showerror(message=normfailmsg)
		else:
			shallwenormalize = tkMessageBox.askokcancel(message=shallwenormalizemsg, title='phononormalizer')
			if shallwenormalize:
			        filelist = ''
				selectedfiles = self.tracklist.listbox.get(0, END)
				for i in range(len(selectedfiles)):
					filelist = filelist + ' ' + selectedfiles[i]
			        normalizecmd = 'normalize -m ' + filelist
				self.pp = popen2.Popen4(normalizecmd)
				print 'Phononormalizer: Starting process "normalize" at PID ' + str(self.pp.pid)
				self.ppp = self.pp.fromchild
				self.frame.after(1000, self.getmsg)


	def getmsg(self):
		if self.pp.poll() == -1:
			bb = self.ppp.read(100)
			print bb
            		self.frame.after(1000, self.getmsg)
		else:
			print 'Phonormalizer: finished'

With getmsg() I want to capture normalize's  output for a window with a progress meter, but with this function normalizing a few
test files which normally takes about 2 or 3 seconds takes more than a minute.

Thanks for your patience with silly newbies like me

Michael




More information about the Tutor mailing list