问题描述
我正在使用ipdb调试器在本地调试多线程Web应用程序(Django,Plone). ipdb似乎经常因为在调试提示符下发生自动重载而感到困惑.由此产生的堆栈跟踪信息
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
此后,要么无法关闭程序(挂起线程),要么ipdb本身停止工作.
After this, either the program cannot be closed (hanging threads) or ipdb itself stops working.
是否可以通过ipdb缓解此问题,并使它更安全地支持多线程/自动重装?
Is there a way to migitate this issue with ipdb and make it more multi-thread / autoreload safe?
编辑:稍微澄清了这个问题,因为我认为这可能是IPython潜在的问题.使IPython仅仅丢弃重载时的历史记录或禁用有问题的IPython SQLite写其他方式,可能有某种解决方法.
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.
推荐答案
您始终可以在单线程模式下运行Django
You can always run Django in single threaded mode
python manage.py runserver --nothreading
这篇关于ipdb,多个线程和自动重载程序导致ProgrammingError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!