提交 dd168c59 authored 作者: nouiz's avatar nouiz

Merge pull request #1358 from delallea/on_opt_error_pdb

Added 'on_opt_error=pdb' to fall into pdb on error
...@@ -310,13 +310,13 @@ import theano and print the config variable, as in: ...@@ -310,13 +310,13 @@ import theano and print the config variable, as in:
.. attribute:: on_opt_error .. attribute:: on_opt_error
String value: 'warn' or 'raise' String value: 'warn', 'raise' or 'pdb'
Default: 'warn' Default: 'warn'
When a crash occurs while trying to apply some optimization, either warn When a crash occurs while trying to apply some optimization, either warn
the user and skip this optimization ('warn'), or raise the exception the user and skip this optimization ('warn'), raise the exception
('raise'). ('raise'), or fall into the pdb debugger ('pdb').
.. attribute:: on_shape_error .. attribute:: on_shape_error
......
...@@ -158,9 +158,9 @@ AddConfigVar('optimizer', ...@@ -158,9 +158,9 @@ AddConfigVar('optimizer',
in_c_key=False) in_c_key=False)
AddConfigVar('on_opt_error', AddConfigVar('on_opt_error',
("What to do when an optimization crashes: warn and skip it, or raise " ("What to do when an optimization crashes: warn and skip it, raise "
"the exception"), "the exception, or fall into the pdb debugger."),
EnumStr('warn', 'raise'), EnumStr('warn', 'raise', 'pdb'),
in_c_key=False) in_c_key=False)
......
...@@ -5,6 +5,7 @@ amount of useful generic optimization tools. ...@@ -5,6 +5,7 @@ amount of useful generic optimization tools.
import copy import copy
import logging import logging
import pdb
import sys import sys
import time import time
...@@ -147,6 +148,8 @@ class SeqOptimizer(Optimizer, list): ...@@ -147,6 +148,8 @@ class SeqOptimizer(Optimizer, list):
_logger.error(traceback.format_exc()) _logger.error(traceback.format_exc())
if config.on_opt_error == 'raise': if config.on_opt_error == 'raise':
raise exc raise exc
elif config.on_opt_error == 'pdb':
pdb.post_mortem(sys.exc_info()[2])
def __init__(self, *opts, **kw): def __init__(self, *opts, **kw):
"""WRITEME""" """WRITEME"""
...@@ -1084,7 +1087,11 @@ class NavigatorOptimizer(Optimizer): ...@@ -1084,7 +1087,11 @@ class NavigatorOptimizer(Optimizer):
_logger.error("Optimization failure due to: %s" % str(local_opt)) _logger.error("Optimization failure due to: %s" % str(local_opt))
_logger.error("TRACEBACK:") _logger.error("TRACEBACK:")
_logger.error(traceback.format_exc()) _logger.error(traceback.format_exc())
if isinstance(exc, AssertionError) or config.on_opt_error == 'raise': if config.on_opt_error == 'pdb':
pdb.post_mortem(sys.exc_info()[2])
elif isinstance(exc, AssertionError) or config.on_opt_error == 'raise':
# We always crash on AssertionError because something may be
# seriously wrong if such an exception is raised.
raise exc raise exc
@staticmethod @staticmethod
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论