首页 > 解决方案 > 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

标签: pythonlinuxmultithreadinggeventgreenlets

解决方案


推荐阅读