1

I found this which allows to break on exception.

Break on exception in pydev

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.

Community
  • 1
  • 1
evan54
  • 3,585
  • 5
  • 34
  • 61

1 Answers1

1

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:

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.

loopbackbee
  • 21,962
  • 10
  • 62
  • 97