MySQL Forums
Forum List  »  Connector/Python

Re: thread safe MySQLdb cursors?
Posted by: stefan sonnenberg
Date: July 28, 2006 12:02AM

Sharing things among threads is always difficult because of
the shared adress space (in terms of a process).
The only chance would be to do something with semaphores,
but that is probably not what you want, because that would limit
the use of the cursor to one thread at any time.
And what would you expect if you open a cursor in thread A,
read some rows, thread B starts, takes the cursor, reads some rows
and then A would read even more.
The "best" would be that A sees a "gap" in rows.
The worst (and most likely) would be a more diverse and not so easy to track
down behaviour.
Just open a new db connection with each thread, or implement some sort
of connection pooling.

And this is not what is ment with thread-safe.



Edited 1 time(s). Last edit at 07/28/2006 12:04AM by stefan sonnenberg.

Options: ReplyQuote


Subject
Written By
Posted
Re: thread safe MySQLdb cursors?
July 28, 2006 12:02AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.