多处理错误 Snowflake Python Connector with flask_socketio

Multiprocessing error Snowflake Python Connector with flask_socketio

我在尝试使用 python 的雪花连接器与 flask_socketio 和 eventlet 对雪花进行 运行 查询时收到以下错误。它似乎仅在猴子修补时发生小事件。非常感谢任何帮助。

import snowflake.connector as scon
from flask import Flask
from flask_socketio import SocketIO
import eventlet
eventlet.monkey_patch()

def query():
    # Gets the version
    ctx = scon.connect(
                       user='xxx',
                       password='xxxxxxxx',
                       account='xxxxxx',
                      )
    cs = ctx.cursor()
    try:
        cs.execute("SELECT current_version()")
        one = cs.fetchone()
        return 'Snowflake version={}'.format(one[0])
    finally:
        cs.close()

app = Flask(__name__)
socketio = SocketIO(app)


@app.route('/')
def query_route():
    return query()

socketio.run(app,debug=False, host='localhost', port=5000)

收到错误:

Traceback (most recent call last):
  File "/home/chad/miniconda2/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/home/chad/miniconda2/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/chad/miniconda2/lib/python2.7/multiprocessing/pool.py", line 327, in _handle_workers
    while thread._state == RUN or (pool._cache and thread._state != TERMINATE):
AttributeError: '_MainThread' object has no attribute '_state'

Exception in thread Thread-6:
Traceback (most recent call last):
  File "/home/chad/miniconda2/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/home/chad/miniconda2/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/chad/miniconda2/lib/python2.7/multiprocessing/pool.py", line 363, in _handle_tasks
    cache[job]._set(ind + 1, (False, ex))
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

多处理包与 Eventlet 不兼容。 Here 是 Evenlet 维护者的评论。

您可能应该考虑将该功能移动到一个不受 Eventlet 约束的单独进程(可能是另一个微服务)。