improving performance of writing into a pipe

Michael Torrie torriem at gmail.com
Mon Feb 18 19:12:01 CET 2013


On 02/18/2013 10:00 AM, mikprog at gmail.com wrote:
> [..]
>>
>> I don't see an exception in your answer. Where did you put it for us?
>>
> 
> well I just did print a message:
> 
>     PIPEPATH = ["/tmp/mypipe"]
> 
> [..]
>         try:
>             self.process = os.popen( self.PIPEPATH, 'w')
>         except:
>             print "Error while trying opening the pipe!"
>             print "check: ", self.PIPEPATH
>             exit()
> 
> I see the error messages.

Unfortunately your attempt to catch this exception is hiding the true
cause.  You need to give us the actual exception.  Otherwise it could be
anything from self.PIPEPATH not existing to who knows what.

Almost never do you want to catch all exceptions like you're doing.  You
should only catch the specific exceptions you know how to deal with in
your code.

For testing purposes, if your code really is as you put it, then
catching exceptions is kind of silly since you're just re-raising the
exception (sort of) but without any contextual information that would
make the error meaningful.




More information about the Python-list mailing list