Hi all,
What is the behavior of cx_Oracle cursors when the connection object is used by different threads? How would generators affect this behavior? Specifically...
Edit: The original example function was incorrect; a generator was being returned by a sub function, yield
wasn't used directly in the loop. This clarifies when finally
is executed (after return
does), but still doesn't answer whether a cursor can be used if another thread starts using the connection object the cursor was created from. It actually seems (in python 2.4, at least), try...finally
with yield
causes a syntax error.
def Get()
conn = pool.get()
try:
cursor = conn.cursor()
cursor.execute("select * from table ...")
return IterRows(cursor)
finally:
pool.put(conn)
def IterRows(cursor):
for r in cursor:
yield r
Get()
is a function called by multiple threads. The connections are created with the threaded=False
argument.
I'm wondering...
- Is thread 1's
cursor
object still usable if thread 2 comes along and uses the same connection object? If not, what might happen?
The behavior i'm seeing is an exception in cx_Oracle talking about a protocol error, and then a segfault follows.