首页 > 解决方案 > python gevent LoopExit:'此操作将永远阻塞'

问题描述

我正在使用 python 的 gevent 从烧瓶端点调用的多个 API url 获取数据。我的代码结构如下:

我有一个包含端点的视图文件。相应的视图函数调用一个包装文件。然后这个包装函数为所有可用的 url 生成所有 greenlet。包装函数的代码如下所示:

URL_MAP = {
    'url-0001' : 'SpecificModule'
}

pool = []

for url_id, module in URL_MAP.iteritems():
    # get_url_instance imports the module and creates an object of the class.
    url_instance = get_url_instance(url_id)

    if url_instance:
        # spawn a greenlet
        pool.append(gevent.spawn(url_instance.get_data))

gevent.joinall(pool)

但不幸的是,当我尝试通过 Postman 访问端点时,它会在服务器上引发以下错误:

LoopExit: ('This operation would block forever', <Hub at 0x7f506064eaf0 epoll pending=0 ref=0 fileno=4>)

关于我所缺少的任何线索?

标签: pythongevent

解决方案


推荐阅读