Control the automatic calling of the pdb interactive debugger. Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without argument it works as a toggle. When an exception is triggered, IPython can optionally call the interactive pdb debugger after the tr
(self, parameter_s='')
| 390 | |
| 391 | @line_magic |
| 392 | def pdb(self, parameter_s=''): |
| 393 | """Control the automatic calling of the pdb interactive debugger. |
| 394 | |
| 395 | Call as '%pdb on', '%pdb 1', '%pdb off' or '%pdb 0'. If called without |
| 396 | argument it works as a toggle. |
| 397 | |
| 398 | When an exception is triggered, IPython can optionally call the |
| 399 | interactive pdb debugger after the traceback printout. %pdb toggles |
| 400 | this feature on and off. |
| 401 | |
| 402 | The initial state of this feature is set in your configuration |
| 403 | file (the option is ``InteractiveShell.pdb``). |
| 404 | |
| 405 | If you want to just activate the debugger AFTER an exception has fired, |
| 406 | without having to type '%pdb on' and rerunning your code, you can use |
| 407 | the %debug magic.""" |
| 408 | |
| 409 | par = parameter_s.strip().lower() |
| 410 | |
| 411 | if par: |
| 412 | try: |
| 413 | new_pdb = {'off':0,'0':0,'on':1,'1':1}[par] |
| 414 | except KeyError: |
| 415 | print ('Incorrect argument. Use on/1, off/0, ' |
| 416 | 'or nothing for a toggle.') |
| 417 | return |
| 418 | else: |
| 419 | # toggle |
| 420 | new_pdb = not self.shell.call_pdb |
| 421 | |
| 422 | # set on the shell |
| 423 | self.shell.call_pdb = new_pdb |
| 424 | print('Automatic pdb calling has been turned',on_off(new_pdb)) |
| 425 | |
| 426 | @skip_doctest |
| 427 | @magic_arguments.magic_arguments() |