Reputation: 10751
I have a script that runs a brian2
neural-network simulation. Recently, the script has been producing warnings that originate deep in scipy
, in a module called _dumbdbm_patched
. In order to debug this issue, I've inserted
import pdb
pdb.set_trace()
into the scipy
source code installed on my computer. When I run my script in IPython
, it stops at the breakpoint I've set, but the (Pdb)
prompt never displays. Only after I've executed a keyboard interrupt does the prompt reveal itself -- just before the KeyboardInterrupt
exits 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 thing happens when I make the call directly from the shell, as in
$ python ardid.py --k 1 --g fig_4
Why is this happening? How can I get pdb
to work inside scipy
this way?
Note: Nothing in my script is threaded.
Upvotes: 3
Views: 1786
Reputation: 31
Is your stdout being directed somewhere else? I was having the same problem when running a Python script from a shell (bash). I was running something like
python script_with_pdb_trace.py > output.py
It didn't give the PDB prompt until I just ran
python script_with_pdb_trace.py
Upvotes: 3
Reputation: 65
I would try 2 solution. I am a beginner to python
1-- Try without giving any arguments i.e python ardid.py
2-- Sometimes It happened to me that there was no prompt but I can write the pdb commands s, n () 3-- comment out keyboardinterrupt exception.
Upvotes: 1