1

I receive the following errors when attempting to run a query against snowflake using the snowflake connector for python with flask_socketio and eventlet.. It appears to occur only when monkey patching eventlet. Any help with this is greatly appreciated.

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)

Error Received:

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'

1 Answers1

1

The multiprocessing package is incompatible with Eventlet. Here is a comment from the Evenlet maintainer.

You should probably consider moving that functionality to a separate process (another microservice maybe) where you are not bound to Eventlet.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152