Best Python code snippet using localstack_python
pydevd_breakpoints.py
Source:pydevd_breakpoints.py
1from pydevd_constants import *2import pydevd_tracing3import sys4import pydev_log5import pydevd_import_class6_original_excepthook = None7_handle_exceptions = None8import _pydev_threading as threading9threadingCurrentThread = threading.currentThread10from pydevd_comm import GetGlobalDebugger11class ExceptionBreakpoint:12 def __init__(13 self,14 qname,15 notify_always,16 notify_on_terminate,17 notify_on_first_raise_only,18 ):19 exctype = _get_class(qname)20 self.qname = qname21 if exctype is not None:22 self.name = exctype.__name__23 else:24 self.name = None25 self.notify_on_terminate = notify_on_terminate26 self.notify_always = notify_always27 self.notify_on_first_raise_only = notify_on_first_raise_only28 self.type = exctype29 def __str__(self):30 return self.qname31class LineBreakpoint(object):32 def __init__(self, line, condition, func_name, expression):33 self.line = line34 self.condition = condition35 self.func_name = func_name36 self.expression = expression37def get_exception_full_qname(exctype):38 if not exctype:39 return None40 return str(exctype.__module__) + '.' + exctype.__name__41def get_exception_name(exctype):42 if not exctype:43 return None44 return exctype.__name__45def get_exception_breakpoint(exctype, exceptions):46 exception_full_qname = get_exception_full_qname(exctype)47 exc = None48 if exceptions is not None:49 try:50 return exceptions[exception_full_qname]51 except KeyError:52 for exception_breakpoint in DictIterValues(exceptions):53 if exception_breakpoint.type is not None and issubclass(exctype, exception_breakpoint.type):54 if exc is None or issubclass(exception_breakpoint.type, exc.type):55 exc = exception_breakpoint56 return exc57#=======================================================================================================================58# _excepthook59#=======================================================================================================================60def _excepthook(exctype, value, tb):61 global _handle_exceptions62 if _handle_exceptions:63 exception_breakpoint = get_exception_breakpoint(exctype, _handle_exceptions)64 else:65 exception_breakpoint = None66 #Always call the original excepthook before going on to call the debugger post mortem to show it.67 _original_excepthook(exctype, value, tb)68 if not exception_breakpoint:69 return70 if tb is None: #sometimes it can be None, e.g. with GTK71 return72 frames = []73 while tb:74 frames.append(tb.tb_frame)75 tb = tb.tb_next76 thread = threadingCurrentThread()77 frames_byid = dict([(id(frame),frame) for frame in frames])78 frame = frames[-1]79 thread.additionalInfo.exception = (exctype, value, tb)80 thread.additionalInfo.pydev_force_stop_at_exception = (frame, frames_byid)81 thread.additionalInfo.message = exception_breakpoint.qname82 debugger = GetGlobalDebugger()83 pydevd_tracing.SetTrace(None) #no tracing from here84 pydev_log.debug('Handling post-mortem stop on exception breakpoint %s'% exception_breakpoint.qname)85 debugger.handle_post_mortem_stop(thread.additionalInfo, thread)86#=======================================================================================================================87# _set_pm_excepthook88#=======================================================================================================================89def _set_pm_excepthook(handle_exceptions_dict=None):90 '''91 Should be called to register the excepthook to be used.92 It's only useful for uncaught exceptions. I.e.: exceptions that go up to the excepthook.93 @param handle_exceptions: dict(exception -> ExceptionBreakpoint)94 The exceptions that should be handled.95 '''96 global _handle_exceptions97 global _original_excepthook98 if sys.excepthook != _excepthook:99 #Only keep the original if it's not our own _excepthook (if called many times).100 _original_excepthook = sys.excepthook101 _handle_exceptions = handle_exceptions_dict102 sys.excepthook = _excepthook103def _restore_pm_excepthook():104 global _original_excepthook105 if _original_excepthook:106 sys.excepthook = _original_excepthook107 _original_excepthook = None108def update_exception_hook(dbg):109 if dbg.break_on_uncaught_exceptions:110 _set_pm_excepthook(dbg.break_on_uncaught_exceptions)111 else:112 _restore_pm_excepthook()113def _get_class( kls ):114 if IS_PY24 and "BaseException" == kls:115 kls = "Exception"116 try:117 return eval(kls)118 except:...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!