2015-05-07 53 views
3

我有一个运行brian2神经网络仿真的脚本。最近,脚本一直在产生深度为scipy的警告,其模块名为_dumbdbm_patched。为了调试这个问题,我已经插入pdb.set_trace():脚本在断点处停止,但不显示提示

import pdb 
pdb.set_trace() 

进入scipy源代码安装在我的电脑上。当我在IPython中运行我的脚本时,它会在我设置的断点处停止,但不会显示(Pdb)提示。我执行后,只有一个键盘中断并迅速显露出来 - 在KeyboardInterrupt退出程序之前:

In [2]: run ardid.py --k 1 --g fig_4 
^C> /home/despo/dbliss/lib/python2.7/site-packages/scipy/weave/_dumbdbm_patched.py(163)open() 
-> return _Database(file) 
(Pdb) --------------------------------------------------------------------------- 
KeyboardInterrupt       Traceback (most recent call last) 
/home/despo/dbliss/dopa_net/brian/ardid/ardid.py in <module>() 
    173  # ------------------------------------------------------------------------- 
    174 
--> 175  cii_pfc = brian2.Synapses(pi_pfc, pi_pfc, pre='s_gaba += 1', connect=True) 
    176  cie_pfc = brian2.Synapses(pi_pfc, pe_pfc, pre='s_gaba += 1', connect=True) 
    177 

/home/despo/dbliss/lib/python2.7/site-packages/Brian2-2.0b3+git-py2.7-linux-x86_64.egg/brian2/synapses/synapses.pyc in __init__(self, source, target, model, pre, post, connect, delay, namespace, dtype, codeobj_class, dt, clock, order, method, name) 
    756 
    757   if not connect is False: 
--> 758    self.connect(connect, level=1) 
    759 
    760  def __len__(self): 

/home/despo/dbliss/lib/python2.7/site-packages/Brian2-2.0b3+git-py2.7-linux-x86_64.egg/brian2/synapses/synapses.pyc in connect(self, pre_or_cond, post, p, n, namespace, level) 
    1064         'to an float, is type %s instead.' % type(n)) 
    1065    self._add_synapses(None, None, n, p, condition=pre_or_cond, 
-> 1066        namespace=namespace, level=level+1) 
    1067   else: 
    1068    raise TypeError(('First argument has to be an index or a ' 

/home/despo/dbliss/lib/python2.7/site-packages/Brian2-2.0b3+git-py2.7-linux-x86_64.egg/brian2/synapses/synapses.pyc in _add_synapses(self, sources, targets, n, p, condition, namespace, level) 
    1192            check_units=False, 
    1193            run_namespace=namespace, 
-> 1194            level=level+1) 
    1195    codeobj() 
    1196 

/home/despo/dbliss/lib/python2.7/site-packages/Brian2-2.0b3+git-py2.7-linux-x86_64.egg/brian2/codegen/codeobject.pyc in create_runner_codeobj(group, code, template_name, user_code, variable_indices, name, check_units, needed_variables, additional_variables, level, run_namespace, template_kwds, override_conditional_write, codeobj_class) 
    256 
    257  if codeobj_class is None: 
--> 258   codeobj_class = device.code_object_class(group.codeobj_class) 
    259  else: 
    260   codeobj_class = device.code_object_class(codeobj_class) 

/home/despo/dbliss/lib/python2.7/site-packages/Brian2-2.0b3+git-py2.7-linux-x86_64.egg/brian2/devices/device.pyc in code_object_class(self, codeobj_class) 
    199  def code_object_class(self, codeobj_class=None): 
    200   if codeobj_class is None: 
--> 201    codeobj_class = get_default_codeobject_class() 
    202   return codeobj_class 
    203 

/home/despo/dbliss/lib/python2.7/site-packages/Brian2-2.0b3+git-py2.7-linux-x86_64.egg/brian2/devices/device.pyc in get_default_codeobject_class(pref) 
    77  if isinstance(codeobj_class, str): 
    78   if codeobj_class == 'auto': 
---> 79    return auto_target() 
    80   for target in codegen_targets: 
    81    if target.class_name == codeobj_class: 

/home/despo/dbliss/lib/python2.7/site-packages/Brian2-2.0b3+git-py2.7-linux-x86_64.egg/brian2/devices/device.pyc in auto_target() 
    51       if target.class_name) 
    52   using_fallback = False 
---> 53   if 'weave' in target_dict and target_dict['weave'].is_available(): 
    54    _auto_target = target_dict['weave'] 
    55   elif 'cython' in target_dict and target_dict['cython'].is_available(): 

/home/despo/dbliss/lib/python2.7/site-packages/Brian2-2.0b3+git-py2.7-linux-x86_64.egg/brian2/codegen/runtime/weave_rt/weave_rt.pyc in is_available() 
    135        headers=['<algorithm>', '<limits>'], 
    136        extra_compile_args=extra_compile_args, 
--> 137        verbose=0) 
    138     return True 
    139   except Exception as ex: 

/home/despo/dbliss/lib/python2.7/site-packages/scipy/weave/inline_tools.py in inline(code, arg_names, local_dict, global_dict, force, compiler, verbose, support_code, headers, customize, type_converters, auto_downcast, newarr_converter, **kw) 
    350   # 2. try function catalog 
    351   try: 
--> 352    results = attempt_function_call(code,local_dict,global_dict) 
    353   # 3. build the function 
    354   except ValueError: 

/home/despo/dbliss/lib/python2.7/site-packages/scipy/weave/inline_tools.py in attempt_function_call(code, local_dict, global_dict) 
    419  # 3. try persistent catalog 
    420  module_dir = global_dict.get('__file__',None) 
--> 421  function_list = function_catalog.get_functions(code,module_dir) 
    422  for func in function_list: 
    423   try: 

/home/despo/dbliss/lib/python2.7/site-packages/scipy/weave/catalog.py in get_functions(self, code, module_dir) 
    793   try: 
    794    self.set_module_directory(module_dir) 
--> 795    function_list = self.get_cataloged_functions(code) 
    796    # put function_list in cache to save future lookups. 
    797    if function_list: 

/home/despo/dbliss/lib/python2.7/site-packages/scipy/weave/catalog.py in get_cataloged_functions(self, code) 
    708   function_list = [] 
    709   for path in self.build_search_order(): 
--> 710    cat = get_catalog(path,mode) 
    711    if cat is not None and code in cat: 
    712     # set up the python path so that modules for this 

/home/despo/dbliss/lib/python2.7/site-packages/scipy/weave/catalog.py in get_catalog(module_path, mode) 
    479   and ((dumb and os.path.exists(catalog_file+'.dat')) 
    480     or os.path.exists(catalog_file)): 
--> 481   sh = shelve.open(catalog_file,mode) 
    482  else: 
    483   if mode == 'r': 

/home/despo/dbliss/lib/python2.7/site-packages/scipy/weave/_dumb_shelve.py in open(filename, flag) 
    49  """ 
    50 
---> 51  return DbfilenameShelf(filename, flag) 

/home/despo/dbliss/lib/python2.7/site-packages/scipy/weave/_dumb_shelve.py in __init__(self, filename, flag) 
    20  def __init__(self, filename, flag='c'): 
    21   from . import _dumbdbm_patched 
---> 22   Shelf.__init__(self, _dumbdbm_patched.open(filename, flag)) 
    23 
    24  def __getitem__(self, key): 

/home/despo/dbliss/lib/python2.7/site-packages/scipy/weave/_dumbdbm_patched.py in open(file, flag, mode) 
    161  pdb.set_trace() 
    162 
--> 163  return _Database(file) 

/home/despo/dbliss/lib/python2.7/site-packages/scipy/weave/_dumbdbm_patched.py in open(file, flag, mode) 
    161  pdb.set_trace() 
    162 
--> 163  return _Database(file) 

/usr/local/anaconda-1.9.2/lib/python2.7/bdb.pyc in trace_dispatch(self, frame, event, arg) 
    47    return # None 
    48   if event == 'line': 
---> 49    return self.dispatch_line(frame) 
    50   if event == 'call': 
    51    return self.dispatch_call(frame, arg) 

/usr/local/anaconda-1.9.2/lib/python2.7/bdb.pyc in dispatch_line(self, frame) 
    65  def dispatch_line(self, frame): 
    66   if self.stop_here(frame) or self.break_here(frame): 
---> 67    self.user_line(frame) 
    68    if self.quitting: raise BdbQuit 
    69   return self.trace_dispatch 

/usr/local/anaconda-1.9.2/lib/python2.7/pdb.pyc in user_line(self, frame) 
    156    self._wait_for_mainpyfile = 0 
    157   if self.bp_commands(frame): 
--> 158    self.interaction(frame, None) 
    159 
    160  def bp_commands(self,frame): 

/usr/local/anaconda-1.9.2/lib/python2.7/pdb.pyc in interaction(self, frame, traceback) 
    208   self.setup(frame, traceback) 
    209   self.print_stack_entry(self.stack[self.curindex]) 
--> 210   self.cmdloop() 
    211   self.forget() 
    212 

/usr/local/anaconda-1.9.2/lib/python2.7/cmd.pyc in cmdloop(self, intro) 
    128      if self.use_rawinput: 
    129       try: 
--> 130        line = raw_input(self.prompt) 
    131       except EOFError: 
    132        line = 'EOF' 

KeyboardInterrupt: 

同样的事情发生时,我让直接从外壳的号召,在

$ python ardid.py --k 1 --g fig_4 

这是为什么发生?我怎样才能得到pdb以这种方式在scipy里面工作?

注意:我的脚本中没有任何内容是线程化的。

回答

0

我会尝试2解决方案。我是一个初学者到Python

1--尽量不给任何参数,即python ardid.py

2--有时它发生在我身上,没有提示,但我可以写PDB命令S,N() 3--注释掉键盘中断异常。

+0

#2是一个很好的建议。我会尝试一下。据我所知,#3没有任何意义。 'KeyboardInterrupt'没有写入我的代码;它发生在我脚本执行期间输入'ctrl-C'时。 #1不适用于此脚本;该脚本需要命令行参数。我可以重写脚本以便它不需要这些脚本,但我的目标是让'pdb'与脚本一起工作。 – dbliss

1

你的stdout是否定向到别的地方?从shell(bash)运行Python脚本时遇到同样的问题。我是运行像

python script_with_pdb_trace.py > output.py 

它没有给PDB提示,直到我只是跑

python script_with_pdb_trace.py 
+0

我不是故意重定向它,但我想这可能是我的系统管理员没有意识到它。 – dbliss