6

I am using ipdb debugger to debug multithreaded web applications locally (Django, Plone). Often ipdb seems to get confused because of the autoreload which happens when I am on the debug prompt. The resulting stack trace comes up

/Users/mikko/code/xxxx/venv/lib/python2.7/site-packages/IPython/core/history.pyc in writeout_cache(self, conn)
    605         with self.db_input_cache_lock:
    606             try:
--> 607                 self._writeout_input_cache(conn)
    608             except sqlite3.IntegrityError:
    609                 self.new_session(conn)

/Users/mikko/code/xxxx/venv/lib/python2.7/site-packages/IPython/core/history.pyc in _writeout_input_cache(self, conn)
    589             for line in self.db_input_cache:
    590                 conn.execute("INSERT INTO history VALUES (?, ?, ?, ?)",
--> 591                                 (self.session_number,)+line)
    592
    593     def _writeout_output_cache(self, conn):

ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 4546363392 and this is thread id 140735211872640

After this, either the program cannot be closed (hanging threads) or ipdb itself stops working.

Is there a way to migitate this issue with ipdb and make it more multi-thread / autoreload safe?

EDIT: Clarified the question a bit, as I believe this might be underlying IPython issues. There could be some kind of workaround with making IPython simply discard history on the reload or disabling problematic IPython SQLite writes some other way.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
  • @MIkkoOhtamma, how are you enabling autoreload in ipdb? I know of this extension:https://ipython.org/ipython-doc/3/config/extensions/autoreload.html. If I enable this extension in `ipython`, and if I use `ipdb`, while running the python file in `ipython`, will ipdb automatically reload statements in the python file, when using `n`, `j` etc? – alpha_989 Mar 30 '18 at 16:55
  • Related: https://github.com/gotcha/ipdb/issues/51 – Ciro Santilli OurBigBook.com May 19 '19 at 13:34

1 Answers1

5

You can always run Django in single threaded mode

python manage.py runserver --nothreading
wjandrea
  • 28,235
  • 9
  • 60
  • 81
istib
  • 136
  • 2
  • 4