Skip to content

Hydra does not work with pdb #1237

@ethanabrooks

Description

@ethanabrooks

🐛 Bug

Description

When running pdb as in

python -m pdb myscript.py

the debugger does not allow me to inspect local variables upon exception.

To reproduce

# myscript.py
import hydra

@hydra.main()
def app(cfg) -> None:
    x = 0
    assert False

if __name__ == "__main__":
    app()

Run:

❯ python -m pdb -c continue myscript.py
Traceback (most recent call last):
  File "/Users/ethanbrooks/ppo/myscript.py", line 8, in app
    assert False
AssertionError

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.
The program exited via sys.exit(). Exit status: 1
> /Users/ethanbrooks/ppo/myscript.py(2)<module>()
-> import hydra
(Pdb)

At the prompt, type p x

(Pdb) p x
*** NameError: name 'x' is not defined

Expected Behavior

pdb should work as it does when not using hydra:

def app() -> None:
    x = 0
    assert False

if __name__ == "__main__":
    app()
❯ python -m pdb -c continue myscript.py
Traceback (most recent call last):
  File "/Users/ethanbrooks/miniconda3/envs/ppo/lib/python3.8/pdb.py", line 1704, in main
    pdb._runscript(mainpyfile)
  File "/Users/ethanbrooks/miniconda3/envs/ppo/lib/python3.8/pdb.py", line 1573, in _runscript
    self.run(statement)
  File "/Users/ethanbrooks/miniconda3/envs/ppo/lib/python3.8/bdb.py", line 580, in run
    exec(cmd, globals, locals)
  File "<string>", line 1, in <module>
  File "/Users/ethanbrooks/ppo/myscript.py", line 1, in <module>
    def app() -> None:
  File "/Users/ethanbrooks/ppo/myscript.py", line 3, in app
    assert False
AssertionError
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /Users/ethanbrooks/ppo/myscript.py(3)app()
-> assert False
(Pdb) p x
0

System information

  • Hydra Version : 1.0.4
  • Python version : 3.8
  • Virtual environment type and version : conda 4.9.2
  • Operating system : BigSur 11.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions