python Eclipse - how to break/pause on warning?
Question: I found this which allows to break on exception.

[Break on exception in pydev](http://stackoverflow.com/questions/455552/break-
on-exception-in-pydev/6655894#6655894)

However, what I'd like is to break on a warning. This is the warning I get and
would like if this or another warning are reported to break at that point.

    
    
    RuntimeWarning: invalid value encountered in double_scalars  yv = Nv(v, U*r)/Nv(v, U*r_)
    

Thanks in advance.


Answer: Unlike a exception, which is associated with several flow control mechanisms,
a warning is simply text that is outputted to the console - more exactly, to
the
[`stderr`](https://en.wikipedia.org/wiki/Stderr#Standard_error_.28stderr.29):

A possible way to break on warnings would thus be intercepting calls to
`stderr`:

    
    
    class MyStderr(object):
        def __init__(self, original_stderr):
            self.original_stderr= original_stderr
        def my_break(self):
            import pdb; pdb.set_trace()
        def write(self,*args, **kwargs):
            self.my_break()
            #...
        def writelines(self,*args, **kwargs):
            self.my_break()
            #...
        #...
    import sys
    sys.stderr= MyStderr(sys.stderr)
    

This should launch the interactive `pdb` debugger.

