List Info

Thread: threadpool/dbconns - going back to basics




threadpool/dbconns - going back to basics
user name
2006-05-19 00:04:18
Hi - I have some code which is broken with threadpool=10 and
OK with
threadpool=1.

The nature of the problem is that one method causes rows to
be added to
a table and one method attempts to read them. The second
method cannot
always see the rows added (although i can via MySQL on the
command
line).

After much fiddling i found that setting threadpool=1 makes
the problem
disappear.

The way i handle connections is (I'm happy to admit)
unorthodox and I'd
like it to be better but here's how it is right now.

In the start up script i have got (amongst other stuff)...

#===========================================================
====
# "per thread startup" Functions
#===========================================================
====
def makeAThreadSpecific_MySQLDb_Connection(thread_index):
        # Create a connection and store it in the current
thread
        cherrypy.threadData.MySQLDb_conn =
MySQLdb.Connect(...blah..)
        time.sleep(0.5)

cherrypy.server.onStartThreadList.append(makeAThreadSpecific
_MySQLDb_Connection)

... then in each class that needs to make a connection i
have a
function which looks like this ...

def getDBConn(self):
	self.MySQLDb_conn = cherrypy.threadData.MySQLDb_conn

... this function gets called each time a database
update/select is
about to take place.


OK well I'm pretty sure that this is far from an ideal
setup but is
there something about it which would generate the type of
errors i'm
describing ? This whole pooling thing is something I'm
having
difficulty getting my head around.

I'm using CP 2.1, MySQLdb 1.2 against MySQL 5.x

regards

Richard.

ps - whilst debugging this I have dumped the last few rows
of the table
out to the log in both the 'reader' method and the
'writer' method and
sure enough the 'writer' method shows the row which has
just been added
but the 'reader' method (executed some seconds later as a
the result of
a further click on screen) doesn't show the row which the
'writer'
method did !


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

threadpool/dbconns - going back to basics
user name
2006-05-19 03:56:20
you already have a pool there. from what is see for every
thread
you'll have a db connection.
did the writter add that row at all in the database ? ( did
you force
a commit ? )

On 5/19/06, northof40 <shearichardgmail.com> wrote:
>
> Hi - I have some code which is broken with
threadpool=10 and OK with
> threadpool=1.
>
> The nature of the problem is that one method causes
rows to be added to
> a table and one method attempts to read them. The
second method cannot
> always see the rows added (although i can via MySQL on
the command
> line).
>
> After much fiddling i found that setting threadpool=1
makes the problem
> disappear.
>
> The way i handle connections is (I'm happy to admit)
unorthodox and I'd
> like it to be better but here's how it is right now.
>
> In the start up script i have got (amongst other
stuff)...
>
>
#===========================================================
====
> # "per thread startup" Functions
>
#===========================================================
====
> def
makeAThreadSpecific_MySQLDb_Connection(thread_index):
>         # Create a connection and store it in the
current thread
>         cherrypy.threadData.MySQLDb_conn =
MySQLdb.Connect(...blah..)
>         time.sleep(0.5)
>
>
cherrypy.server.onStartThreadList.append(makeAThreadSpecific
_MySQLDb_Connection)
>
> ... then in each class that needs to make a connection
i have a
> function which looks like this ...
>
> def getDBConn(self):
>         self.MySQLDb_conn =
cherrypy.threadData.MySQLDb_conn
>
> ... this function gets called each time a database
update/select is
> about to take place.
>
>
> OK well I'm pretty sure that this is far from an ideal
setup but is
> there something about it which would generate the type
of errors i'm
> describing ? This whole pooling thing is something I'm
having
> difficulty getting my head around.
>
> I'm using CP 2.1, MySQLdb 1.2 against MySQL 5.x
>
> regards
>
> Richard.
>
> ps - whilst debugging this I have dumped the last few
rows of the table
> out to the log in both the 'reader' method and the
'writer' method and
> sure enough the 'writer' method shows the row which
has just been added
> but the 'reader' method (executed some seconds later
as a the result of
> a further click on screen) doesn't show the row which
the 'writer'
> method did !
>
>
> >
>


-- 
http://ionel.zapto.org
ionel.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at http://
groups.google.com/group/cherrypy-users
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )