目前,我在Ubuntu 14.04上運行的流浪漢服務器Django的服務器時,我通過使用簡單的python manage.py runserver 0.0.0.0:8000
神祕的錯誤使用帶有grequests
測試所有我的Django的模塊,因爲我連接到Django的web服務器使用Chrome通過http://localhost:8000
且服務器上虛擬機上運行,我是通過以下設置的使用端口轉發在Vagrantfile
config.vm.network "forwarded_port", guest: 8000, host: 8000
一切運行正常(所有模塊/視圖/測試功能如預期),但是,自從我開始使用grequests
我得到這個奇怪的錯誤,我沒有使用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在多個模塊中使用,我基本上需要在每個grequests導入下調用'monkey.patch_all()'然後呢? 此外,滾動你自己的異步請求邏輯似乎有點苛刻。是否有一些我不知道的重大缺陷? – AlanSTACK
另一個後續,你可能會指向我一個替代grequests?我目前正在使用它來一次處理多個其他API調用(例如,將PATCH請求發送給某些僅支持一次編輯一個API的API) – AlanSTACK
我不知道一個好的選擇。你必須建立自己的 – karthikr