Accessing a database from a multithreaded application

Frithiof Andreas Jensen frithiof.jensen at die_spammer_die.ericsson.com
Wed Nov 23 08:55:01 EST 2005


"Alan Kemp" <google at alankemp.com> wrote in message
news:1132718548.824776.130760 at g44g2000cwa.googlegroups.com...
> Hi,

> Can someone suggest a better (ie, valid) strategy for this?

Pass the connection to the thread as a parameter and use it to create a
cursor local to the thread. You may have to create a connection per thread
also - in some database implementations connections are "global" like
cursors are. Cursors are throwaway things anyway.

> Should I
> be using a Queue to make a list of db requests/results to get accross
> the thread boundary (erg, that sounds nasty)?

Maybe - it is safest to limit the amount of threads/cursors/connections that
can be created by people one does not know.

> Should each client
> thread create its own connection/cursor to the database?  Would that
> even work, wont there be locking issues?

Yes, and maybe; one connection/cursor for each thread will always work.

>
> Any suggestions or pointers in the direction of more information would
> be greatly appreciated.

Maybe use queues to pass the requests to a pool of threads; there might be a
limit to how many connection/cursors that can be created at the same time -- 
and some DOS tool will find it.

>
> Thanks for your time,
>
> Alan
>





More information about the Python-list mailing list