刚刚安装了 django-3.0,我习惯插入 ipdb 来停止运行时并检查函数。 使用以前的版本,它工作正常。 有什么办法让它工作吗?
> /home/tec1/workspace/static_site/stagen/hmi/views.py(11)dispatch()
10 def dispatch(self, request, *args, **kwargs):
---> 11 import ipdb; ipdb.set_trace()
12
127.0.0.1 - - [11/Dec/2019 15:52:07] "GET /pg/blog/g/ HTTP/1.1" 500 -
Traceback (most recent call last):
File "/home/tec1/.local/share/virtualenvs/static_site-l8CYf1lN/lib/python3.7/site-packages/django/contrib/staticfiles/handlers.py", line 68, in __call__
return self.application(environ, start_response)
File "/home/tec1/.local/share/virtualenvs/static_site-l8CYf1lN/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 133, in __call__
response = self.get_response(request)
File "/home/tec1/.local/share/virtualenvs/static_site-l8CYf1lN/lib/python3.7/site-packages/django/core/handlers/base.py", line 75, in get_response
response = self._middleware_chain(request)
File "/home/tec1/.local/share/virtualenvs/static_site-l8CYf1lN/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/tec1/.local/share/virtualenvs/static_site-l8CYf1lN/lib/python3.7/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "/home/tec1/.local/share/virtualenvs/static_site-l8CYf1lN/lib/python3.7/site-packages/django/core/handlers/exception.py", line 125, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "/home/tec1/.local/share/virtualenvs/static_site-l8CYf1lN/lib/python3.7/site-packages/django_extensions/management/technical_response.py", line 37, in null_technical_500_response
six.reraise(exc_type, exc_value, tb)
File "/home/tec1/.local/share/virtualenvs/static_site-l8CYf1lN/lib/python3.7/site-packages/six.py", line 695, in reraise
raise value.with_traceback(tb)
File "/home/tec1/.local/share/virtualenvs/static_site-l8CYf1lN/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/tec1/.local/share/virtualenvs/static_site-l8CYf1lN/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/tec1/.local/share/virtualenvs/static_site-l8CYf1lN/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/tec1/.local/share/virtualenvs/static_site-l8CYf1lN/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/home/tec1/workspace/static_site/stagen/hmi/views.py", line 11, in dispatch
import ipdb; ipdb.set_trace()
File "/usr/lib/python3.7/bdb.py", line 92, in trace_dispatch
return self.dispatch_return(frame, arg)
File "/usr/lib/python3.7/bdb.py", line 151, in dispatch_return
self.user_return(frame, arg)
File "/usr/lib/python3.7/pdb.py", line 291, in user_return
self.interaction(frame, None)
File "/home/tec1/.local/share/virtualenvs/static_site-l8CYf1lN/lib/python3.7/site-packages/IPython/core/debugger.py", line 294, in interaction
OldPdb.interaction(self, frame, traceback)
File "/home/tec1/.local/share/virtualenvs/static_site-l8CYf1lN/lib/python3.7/site-packages/pdb.py", line 231, in interaction
File "/usr/lib/python3.7/pdb.py", line 319, in _cmdloop
self.cmdloop()
File "/home/tec1/.local/share/virtualenvs/static_site-l8CYf1lN/lib/python3.7/site-packages/IPython/terminal/debugger.py", line 97, in cmdloop
line = self.pt_app.prompt() # reset_current_buffer=True)
File "/home/tec1/.local/share/virtualenvs/static_site-l8CYf1lN/lib/python3.7/site-packages/prompt_toolkit/shortcuts/prompt.py", line 986, in prompt
return self.app.run()
File "/home/tec1/.local/share/virtualenvs/static_site-l8CYf1lN/lib/python3.7/site-packages/prompt_toolkit/application/application.py", line 788, in run
return get_event_loop().run_until_complete(self.run_async(pre_run=pre_run))
File "/usr/lib/python3.7/asyncio/events.py", line 644, in get_event_loop
% threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'Thread-2'.
127.0.0.1 - - [11/Dec/2019 15:52:07] "GET /pg/blog/g/?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
127.0.0.1 - - [11/Dec/2019 15:52:07] "GET /pg/blog/g/?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1" 200 -
我遇到了同样的问题。如果您使用的是 Python 3.7(根据您的跟踪,看起来您确实如此(,则可以改用新的 Python 断点 ((。
基本上,您将替换
import ipdb; ipdb.set_trace()
由
breakpoint()
查看 https://www.python.org/dev/peps/pep-0553/在那里,您还可以了解如何设置更多花哨的断点。