问题描述
尝试在 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,[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
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)