python - gevent.hub.LoopExit:此操作将永远阻塞
问题描述
尝试在 Python 中使用 select.select 来监视 /proc/ 下的某些内容。最初,它抛出
r, w, x = select.select([],[],[fd])
AttributeError: 'function' object has no attribute 'select'
由于我们使用的是 gevents,因此使用它来摆脱上述错误:
from gevent import monkey, select
monkey.patch_all()
现在,我面临另一个错误,我似乎没有使用 gevent 不喜欢的任何东西(就像我们应该使用 gevent.sleep 而不是 sleep)。这是代码:
from gevent import monkey, select
monkey.patch_all()
file_dp = open("/proc/<>")
while True:
r, w, x = select.select([],[],[fd])
file_dp.seek(0)
print(file_dp.read())
这是错误:
Traceback (most recent call last):
File "read.py", line 8, in <module>
read, write, exc = select.select([],[],[fd])
File "/usr/lib64/python2.9/site-packages/gevent/select.py", line 69, in select
result.event.wait(timeout=timeout)
File "/usr/lib64/python2.9/site-packages/gevent/event.py", line 77, in wait
result = self.hub.switch()
File "/usr/lib64/python2.9/site-packages/gevent/hub.py", line 331, in switch
return greenlet.switch(self)
gevent.hub.LoopExit: This operation would block forever
解决方案
推荐阅读
- c++ - 在 C++ 中解析长字符串的好习惯是什么?
- oracle-apex - 使用 API 进行 PL/SQL 输入验证
- python - 无法将每日情绪评分与每日价格合并
- python - 单击没有使用 selenium 的 id 的提交按钮
- google-chrome - 谷歌浏览器屏幕共享历史
- json - ElasticSearch 特定 JSON
- python - 使用 pyspark 转换时 databricks 和 Google Colab 的不同结果
- vue.js - Gridsome 查找当前 URL
- jestjs - 将多个模拟文件/服务组合成一行
- subprocess - Python嵌套子进程实时输出