Python 使用gevent.queue.queue.get():gevent.hub.LoopExit:';此操作将永远阻止';
在过去的几天里,我一直在尝试将事件流集成到我的flask应用程序中,在本地测试中取得了很好的结果,但在服务器上运行带有uWSGI的应用程序时,结果有些糟糕。我的代码基本上是建立在烧瓶的基础上的。我正在使用Python 使用gevent.queue.queue.get():gevent.hub.LoopExit:';此操作将永远阻止';,python,multithreading,flask,uwsgi,gevent,Python,Multithreading,Flask,Uwsgi,Gevent,在过去的几天里,我一直在尝试将事件流集成到我的flask应用程序中,在本地测试中取得了很好的结果,但在服务器上运行带有uWSGI的应用程序时,结果有些糟糕。我的代码基本上是建立在烧瓶的基础上的。我正在使用python3.4.2 问题 在我的uWSGI服务器上运行应用程序时,每当客户端尝试连接到/streaming端点时,就会引发gevent.hub.LoopExit:“此操作将永远被阻止”。。我的假设是,这是由于无限期地对空队列调用get()造成的 完全回溯: Traceback (most r
python3.4.2
问题
在我的uWSGI服务器上运行应用程序时,每当客户端尝试连接到/streaming
端点时,就会引发gevent.hub.LoopExit:“此操作将永远被阻止”。
。我的假设是,这是由于无限期地对空队列调用get()
造成的
完全回溯:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/werkzeug/wsgi.py", line 691, in __next__
return self._next()
File "/usr/lib/python3/dist-packages/werkzeug/wrappers.py", line 81, in _iter_encoded
for item in iterable:
File "./voting/__init__.py", line 49, in gen
result = queue.get(block=True)
File "/usr/local/lib/python3.4/dist-packages/gevent/queue.py", line 284, in get
return self.__get_or_peek(self._get, block, timeout)
File "/usr/local/lib/python3.4/dist-packages/gevent/queue.py", line 261, in __get_or_peek
result = waiter.get()
File "/usr/local/lib/python3.4/dist-packages/gevent/hub.py", line 878, in get
return self.hub.switch()
File "/usr/local/lib/python3.4/dist-packages/gevent/hub.py", line 609, in switch
return greenlet.switch(self)
gevent.hub.LoopExit: ('This operation would block forever', <Hub at 0x7f717f40f5a0 epoll default pending=0 ref=0 fileno=6>)
将事件添加到队列:
def notify():
msg = {"type": "users", "data": db_get_all_registered(session_id)}
subscriptions.add_item(session_id, msg) # Adds the item to the relevant queues.
gevent.spawn(notify)
如前所述,它在本地运行良好,使用werkzeug
:
from app import app
from gevent.wsgi import WSGIServer
from werkzeug.debug import DebuggedApplication
a = DebuggedApplication(app, evalex=True)
server = WSGIServer(("", 5000), a)
server.serve_forever()
我试过的
- 使用
进行Monkey修补Monkey.patch_all()
- 从
切换到队列
可连接队列
与gevent.sleep(0)
Queue.get()结合使用
解决这一问题的方法是安排其他Greenlet运行。例如,与其生成一个greenlet按需通知,不如安排这样一个greenlet已经在自己的队列中运行并阻塞。Aha这很有意义。我想这就是我在使用图书馆之前没有学习图书馆的原因。你解决了你的问题吗?
from app import app
from gevent.wsgi import WSGIServer
from werkzeug.debug import DebuggedApplication
a = DebuggedApplication(app, evalex=True)
server = WSGIServer(("", 5000), a)
server.serve_forever()