django - 在线程中创建的 SQLite 对象只能在具有 Django 2.2.2 和 ipdb 的同一线程中使用

标签 django python-3.x postgresql celery ipdb

我将我的 Django 项目更新到版本 2.2.2,现在当我调用 ipdb 进行调试时,服务器告诉我那个错误。如果我回到 Django 2.2.1,错误就会消失。

System check identified no issues (0 silenced).
June 06, 2019 - 08:19:36
Django version 2.2.2, using settings 'laserapp.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
> /home/lynde/public_html/laserapp/gestion/views.py(192)get_context_data()
    191         import ipdb; ipdb.set_trace()
--> 192         context = super(ResumeOrderCodeView, self).get_context_data(**kwargs)
    193         try:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 60, in execute
    super().execute(*args, **options)
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 95, in handle
    self.run(**options)
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 102, in run
    autoreload.run_with_reloader(self.inner_run, **options)
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 585, in run_with_reloader
    start_django(reloader, main_func, *args, **kwargs)
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 570, in start_django
    reloader.run(django_main_thread)
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 288, in run
    self.run_loop()
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 294, in run_loop
    next(ticker)
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 334, in tick
    for filepath, mtime in self.snapshot_files():
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 350, in snapshot_files
    for file in self.watched_files():
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 249, in watched_files
    yield from iter_all_python_module_files()
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 103, in iter_all_python_module_files
    return iter_modules_and_files(modules, frozenset(_error_files))
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/django/utils/autoreload.py", line 120, in iter_modules_and_files
    sys_file_paths.append(module.__file__)
AttributeError: module '__main__' has no attribute '__file__'

If you suspect this is an IPython bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@python.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    %config Application.verbose_crash=True

Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/IPython/core/history.py", line 780, in writeout_cache
    self._writeout_input_cache(conn)
  File "/home/lynde/public_html/env/laser/lib/python3.6/site-packages/IPython/core/history.py", line 764, in _writeout_input_cache
    (self.session_number,)+line)
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 140030717908736 and this is thread id 140031011022656.

有人能知道那里有什么问题吗?我在本地机器上使用 django runserver,使用 celery 和 postgresql 数据库。

谢谢!! :)

最佳答案

尝试使用 --reload 标志来运行 runserver。 ./manage.py runserver --noreload

它会停止服务器在代码更改时重新加载,但我认为可以避免您遇到的问题。

关于django - 在线程中创建的 SQLite 对象只能在具有 Django 2.2.2 和 ipdb 的同一线程中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56472198/

相关文章:

ruby-on-rails - 多态关联的多重内部连接

postgresql - 如何在 PostgreSQL 的更新语句中分配局部变量

django - 如何在 DJango+Wagtail 应用程序中配置和启用 OpenID Connect?

python - 删除包含 ASCII 的字符串

javascript - 在Django项目中通过javascript将数据写入cookie

python - SSL ConnectionResetError 从哪里来?

python-3.x - 从 Pandas df 中选择列/轴进行关联

mysql - 在 mysql 数据库中查找行和时间戳之间的交集

python - 如何通过多种形式过滤一个模型?

django - 配置 Django 开发服务器输出