2

目前,我在 Ubuntu 14.04 上运行 vagrant 服务器,并使用简单的python manage.py runserver 0.0.0.0:8000

由于我使用 chrome through 连接到 django 网络服务器http://localhost:8000并且服务器在 VM 上运行,因此我通过使用以下设置进行端口转发Vagrantfile

config.vm.network "forwarded_port", guest: 8000, host: 8000

一切正常运行(所有模块/视图/测试都按预期运行),但是,自从我开始使用以来,grequests我得到了这个奇怪的错误

Exception happened during processing of request from ('10.0.2.2', 63520)
Traceback (most recent call last):
  File "/home/vagrant/anaconda3/lib/python3.6/socketserver.py", line 639, in process_request_thread
    self.finish_request(request, client_address)
  File "/home/vagrant/anaconda3/lib/python3.6/socketserver.py", line 361, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/home/vagrant/anaconda3/lib/python3.6/socketserver.py", line 696, in __init__
    self.handle()
  File "/home/vagrant/anaconda3/lib/python3.6/site-packages/django/core/servers/basehttp.py", line 159, in handle
    self.raw_requestline = self.rfile.readline(65537)
  File "/home/vagrant/anaconda3/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
  File "/home/vagrant/anaconda3/lib/python3.6/site-packages/gevent/_socket3.py", line 385, in recv_into
    self._wait(self._read_event)
  File "/home/vagrant/anaconda3/lib/python3.6/site-packages/gevent/_socket3.py", line 157, in _wait
    self.hub.wait(watcher)
  File "/home/vagrant/anaconda3/lib/python3.6/site-packages/gevent/hub.py", line 651, in wait
    result = waiter.get()
  File "/home/vagrant/anaconda3/lib/python3.6/site-packages/gevent/hub.py", line 899, in get
    return self.hub.switch()
  File "/home/vagrant/anaconda3/lib/python3.6/site-packages/gevent/hub.py", line 630, in switch
    return RawGreenlet.switch(self)
gevent.hub.LoopExit: ('This operation would block forever', <Hub at 0x7f3b777e8af8 epoll pending=0 ref=0 fileno=34>)

请注意,我没有使用,并且即使没有调用它或其他任何东西grequests,简单地导入它似乎也会导致此错误

有人有想法么?

4

1 回答 1

3

这是底层依赖项之一的问题 - gevent,它覆盖了 python 内置的默认行为,例如time等。

你将不得不猴子补丁。就像是:

from gevent import monkey
monkey.patch_all()

这是相关gevent文档

我最近遇到了这个确切的问题 - 所以停止使用grequests并实现我自己的异步请求逻辑

于 2017-04-17T04:10:46.750 回答