日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

AttributeError: module 'select' has no attribute 'error'解决方法

發布時間:2025/4/16 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 AttributeError: module 'select' has no attribute 'error'解决方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

gevent 實現多協程的時候,出現了上面的錯誤

錯誤的代碼如下:

import requests from gevent import monkey monkey.patch_all() import gevent def f(url):print('GET: %s' % url)data = requests.get(url).textprint('%d bytes received from %s.' % (len(data), url))gevent.joinall([gevent.spawn(f, 'https://www.python.org/'),gevent.spawn(f, 'https://www.yahoo.com/'),gevent.spawn(f, 'https://github.com/'), ])

比較糾結,因為在網上大家似乎都是這么寫的呀?為什么我會報錯了??
查了半天也沒查到有關的信息, 后來我在github上看到一篇講gevent - ‘module’ object has no attribute ‘epoll’的時候,雖然也沒有看到些上面,但是看到評論區中有人說了這樣的話

I agree that monkey patching has to be done before everything. I have a django app running with uwsgi+supervisord config. And gevent.monkey.patch_all() was the first line of wsgi.py (which is the entry point to the app). But still this exception was thrown. So either adding –gevent-early-monkey-patch in the uwsgi config or gevent.monkey.patch_all(select=False) in the wsgi.py fixed the error. I’m not sure that this is relevant to the requests or urllib3 libs but just for someone’s information.

看到最后那句話的時候,突然靈光一閃!這不是剛好解釋了我的問題了么?
因為我的報錯正是關于select的呀!雖然我寫的代碼沒有用到那個config,但是我也是在這里遇到了問題了呀!

AttributeError: module ‘select’ has no attribute ‘error’

所以正確的解法應該是:

import requests from gevent import monkey monkey.patch_all(select=False) import gevent def f(url):print('GET: %s' % url)data = requests.get(url).textprint('%d bytes received from %s.' % (len(data), url))gevent.joinall([gevent.spawn(f, 'https://www.python.org/'),gevent.spawn(f, 'https://www.yahoo.com/'),gevent.spawn(f, 'https://github.com/'), ])

然后,我們就可以很愉快的開始我們的表演了:請看下面的gif

嘿嘿嘿~ 這樣我們在不同的協程中,只要遇到了IO或者網絡上的問題,就直接切換了~
Hello gevent~

最后,老套路,宣傳一波自己的公眾號!(求關注哇!)
本人中大一肥宅,歡迎大家關注,請掃下面的二維碼(〃’▽’〃)


如果覺得有幫助的話,可以掃碼,贊賞鼓勵一下!謝謝!


總結

以上是生活随笔為你收集整理的AttributeError: module 'select' has no attribute 'error'解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。