Pymongo仅在PyCharm调试器中出错

时间:2016-03-22 15:41:51

标签: django debugging pycharm pymongo

我在PyCharm中调试代码时遇到了一个非常严重的错误。导致异常的违规行是

a = db.links.list_indexes()

或以下:

db.links.create_index("created", expireAfterSeconds=settings.EXPIRY_PERIOD, background=True)

如果我只是run tests,我的代码在PyCharm中正常运行,而尝试调试它会导致以下错误:

======================================================================
ERROR: test_detail_view (sharescreening.tests.TestIndex)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "sharescreening/tests.py", line 53, in test_detail_view
    response = self.client.get('/')
  File "/home/oznt/.virtualenvs/screenshares/local/lib/python2.7/site-packages/django/test/client.py", line 500, in get
    **extra)
  File "/home/oznt/.virtualenvs/screenshares/local/lib/python2.7/site-packages/django/test/client.py", line 303, in get
    return self.generic('GET', path, secure=secure, **r)
  File "/home/oznt/.virtualenvs/screenshares/local/lib/python2.7/site-packages/django/test/client.py", line 379, in generic
    return self.request(**r)
  File "/home/oznt/.virtualenvs/screenshares/local/lib/python2.7/site-packages/django/test/client.py", line 466, in request
    six.reraise(*exc_info)
  File "/home/oznt/.virtualenvs/screenshares/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 119, in get_response
    resolver_match = resolver.resolve(request.path_info)
  File "/home/oznt/.virtualenvs/screenshares/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 365, in resolve
    for pattern in self.url_patterns:
  File "/home/oznt/.virtualenvs/screenshares/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 401, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/oznt/.virtualenvs/screenshares/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 395, in urlconf_module
    self._urlconf_module = import_module(self.urlconf_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/oznt/.virtualenvs/screenshares/local/lib/python2.7/site-packages/gevent/builtins.py", line 93, in __import__
    result = _import(*args, **kwargs)
  File "sharescreening/urls.py", line 17, in <module>
    from .views import put_links, index, get_shares, ShowDetails
  File "/home/oznt/.virtualenvs/screenshares/local/lib/python2.7/site-packages/gevent/builtins.py", line 93, in __import__
    result = _import(*args, **kwargs)
  File "sharescreening/views.py", line 22, in <module>
    a = db.links.list_indexes()
  File "/home/oznt/.virtualenvs/screenshares/local/lib/python2.7/site-packages/pymongo/collection.py", line 1269, in list_indexes
    with self._socket_for_primary_reads() as (sock_info, slave_ok):
  File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/home/oznt/.virtualenvs/screenshares/local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 699, in _socket_for_reads
    with self._get_socket(read_preference) as sock_info:
  File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/home/oznt/.virtualenvs/screenshares/local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 663, in _get_socket
    server = self._get_topology().select_server(selector)
  File "/home/oznt/.virtualenvs/screenshares/local/lib/python2.7/site-packages/pymongo/topology.py", line 121, in select_server
    address))
  File "/home/oznt/.virtualenvs/screenshares/local/lib/python2.7/site-packages/pymongo/topology.py", line 97, in select_servers
    self._error_message(selector))
ServerSelectionTimeoutError: No servers found yet

----------------------------------------------------------------------
Ran 4 tests in 32.173s

FAILED (errors=1)

我不知道为什么测试在命令行中传递,并且在简单的运行模式下但不在调试模式下。有人可以在这里阐明这个问题吗?

1 个答案:

答案 0 :(得分:0)

事实证明,该问题确实是组合使用或gevent与调试器一起使用的问题。 如果您遇到此问题,可以通过将pycharm版本升级到2006.1来解决。 有关详细信息,请参阅issue in PYCharm tracker