See documents : threadsafety are threadsafety , and I quote,
Currently 2, which means that threads can share module and connections, but not cursors.
Thus, your cursor pool design (where one cursor can be used by different threads) seems to be higher than threadsafety . This is not a connection exchange problem (this is normal since you successfully passed threaded in the connection designer), but cursors. You may want to save each cursor in threading.local after the first thread has used it, so that each thread can have its own "pool" with 1 cursor (but not key optimization, though: creating a new cursor is not hard work).
In answer to your question 2, the finally clause is executed when the generator object (built by calling your Get generator function) is executed - either because it raises StopIteration , or because it is garbage collection (usually because the last link to it just disappeared). For example, if the caller:
def imthecaller(): for i, row in enumerate(Get()): print i, row if i > 1: break
finally is executed after (no more) three lines: yield ed.
source share