MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors

python3.6开启多协程报错


代码

import gevent
from gevent import monkey
monkey.patch_all()  # 把程序变成协作式运行,---异步
from gevent.queue import Queue
import time, requests
from bs4 import BeautifulSoup

报错信息

MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors, including RecursionError on Python 3.6. It may also silently lead to incorrect behaviour on Python 3.7. Please monkey-patch earlier. See https://github.com/gevent/gevent/issues/1016. Modules that had direct imports (NOT patched): ['_shaded_thriftpy.transport._ssl (S:\\development_tools\\development_python\\pycharm\\pycharm\\PyCharm 2019.3.2\\plugins\\python\\helpers\\third_party\\thriftpy\\_shaded_thriftpy\\transport\\_ssl.py)']. 
  monkey.patch_all()  # 把程序变成协作式运行,---异步

看过很多帖子,多数就是把

import gevent
from gevent import monkey
monkey.patch_all()

放在最前面,如上图代码,我已经放在最前面了,但是还是会报相同的错误。下面是环境安装的gevent版本
在这里插入图片描述

换了gevent低版本
在这里插入图片描述
还是提示相同错误,排除gevent版本问题。
之前用的是pycharm 分块代码执行功能,怀疑分块代码运行出错
删除之前写的python文件,新建一个,代码如下:再次运行
新建文件代码:

import gevent
from gevent import monkey
monkey.patch_all()  # 把程序变成协作式运行,---异步
from gevent.queue import Queue
import time, requests
from bs4 import BeautifulSoup

执行结果:

S:\project_environment\environment_python\python-3.6.6\python.exe M:/program_all/pro_python/python_course/crawling/CrawlingVideoTop100.py
Traceback (most recent call last):
  File "M:/program_all/pro_python/python_course/crawling/CrawlingVideoTop100.py", line 82, in <module>
    work.put_nowait(i)
TypeError: put_nowait() takes exactly one argument (0 given)

Process finished with exit code 1

大吉大利,终于不再出现上面的错误了,也算问题解决了。
总结:
解决方案一:

import gevent
from gevent import monkey
monkey.patch_all()

上面三行代码写在所有引入语句最前面。

解决方案二:
删除源文件新建新文件。

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值