A small helper I use to debug some python programs: fromcontextlibimportcontextmanager@contextmanagerdefdebug_error():try:yieldexceptExceptionase:breakpoint()quit()### usagewithdebug_error():x=1y=0x/y# x and y will be avail in pdb You can also put things before the yield (which will run before the with block), and after it (to run at the end of the block.) Anything put after it will run at the end of the block. See @contextmanager for more info. Notes