Как отладить скрипт с отладкой I Python magi c%? - PullRequest
0 голосов
/ 02 февраля 2020

В I Python (в Ubuntu 18.04) я могу запустить сценарий python, и это дает ожидаемое исключение -

Python 3.7.5 (default, Nov  7 2019, 10:50:52) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.12.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: run generate.py                                                                              
usage: generate.py [-h] -i IN_FOLDER -m MODEL -o OUT_FOLD
                   [--mean_shape MEAN_SHAPE] [--eigen_vectors EIGEN_VECTORS]
                   [--template_shape TEMPLATE_SHAPE] [-n NUM_FRAMES]
                   [--temporal_condition] [--tcboost TCBOOST]
generate.py: error: the following arguments are required: -i/--in-folder, -m/--model, -o/--out-fold
An exception has occurred, use %tb to see the full traceback.

SystemExit: 2

Из bash я могу вызвать ipdb и debug тот же сценарий с -

~/dev/venv/3.7/bin/python3.7 -m ipdb generate.py 
/usr/lib/python3.7/runpy.py:125: RuntimeWarning: 'ipdb.__main__' found in sys.modules after import of package 'ipdb', but prior to execution of 'ipdb.__main__'; this may result in unpredictable behaviour
  warn(RuntimeWarning(msg))
> /home/shane/dev/pytorch/eskimez2019.shane/code/generate.py(1)<module>()
----> 1 import argparse
      2 import math
      3 import os

ipdb> n                                                                                              
> /home/shane/dev/pytorch/eskimez2019.shane/code/generate.py(2)<module>()
      1 import argparse
----> 2 import math
      3 import os

ipdb> c                                                                                              
usage: generate.py [-h] -i IN_FOLDER -m MODEL -o OUT_FOLD
                   [--mean_shape MEAN_SHAPE] [--eigen_vectors EIGEN_VECTORS]
                   [--template_shape TEMPLATE_SHAPE] [-n NUM_FRAMES]
                   [--temporal_condition] [--tcboost TCBOOST]
generate.py: error: the following arguments are required: -i/--in-folder, -m/--model, -o/--out-fold
The program exited via sys.exit(). Exit status: 2
> /home/shane/dev/pytorch/eskimez2019.shane/code/generate.py(1)<module>()
----> 1 import argparse
      2 import math
      3 import os

ipdb> q

Однако, когда я пытаюсь отладить из I Python с помощью отладки magi c%, почему происходит сбой с NameError: name 'generate' is not defined?

In [2]: debug generate.py                                                                            
NOTE: Enter 'c' at the ipdb>  prompt to continue execution.
> <string>(1)<module>()

ipdb> c                                                                                              
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
NameError: name 'generate' is not defined
...