Pdb.set_trace (): the script stops at a breakpoint but doesn't show me a prompt

I have a script that runs a neural network simulation brian2

. Recently the script was generating warnings that go deep into scipy

a module called _dumbdbm_patched

. To debug this issue, I pasted

import pdb
pdb.set_trace()

      

into the source code scipy

installed on my computer. When I run my script in IPython

, it stops at the breakpoint I set, but the prompt is (Pdb)

never shown. It is only after I have performed the keyboard interrupt that the prompt reveals itself - before KeyboardInterrupt

exiting the program:

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: 

      

The same happens when I call the call directly from the shell, as in

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

      

Why is this happening? How can I get it to pdb

work internally scipy

this way?

Note. Nothing in my script is threaded.

+3


source to share


2 answers


Is your stdout directing elsewhere? I had the same problem when running a Python script from a shell (bash). I had something like

python script_with_pdb_trace.py > output.py

      



This gave no PDB prompt until I just ran

python script_with_pdb_trace.py

      

+1


source


I would try 2 solutions. I am starting with python

1-- Try without arguments ie python ardid.py



2 - Sometimes I happened that there was no prompt, but I can write the commands pdb s, n () 3 - comment out the exception from the keyboard.

0


source







All Articles