Re: [Modeling-users] Lost connection with mysql
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien <sbi...@us...> - 2003-03-26 20:14:01
|
Hi, so...@la... wrote: > I think S=E9bastien is busy right now, and I hope he > find clear this point. Alas, sorry for not being more reactive, but that's right, I'm really busy these days. > Ansering myself, >=20 > I found the way to avoid this issue by using=20 > ec.lock() and ec.unlock() at each web app request. > (not really usefull for a threaded web app !!)=20 >=20 >=20 > But i really think the doc, isn't clear about this=20 > point. In fact i think that all operation on a=20 > ec should be locked, even fetching ( !=3D the doc ). > Cause if you don't, you will get some strange=20 > behaviours meanly in the database adapator, that > cause a segfault in the mysql one. You're right indeed. Here is the problem: >>> import MySQLdb >>> MySQLdb.threadsafety 1 Quoted from http://www.python.org/topics/database/DatabaseAPI-2.0.html: threadsafety Integer constant stating the level of thread safety the interface supports. Possible values are: 0 =3D Threads may not share the module. 1 =3D Threads may share the module, but not connections. 2 =3D Threads may share the module and connections. 3 =3D Threads may share the module, connections and cursors. Hence the problem, because the framework shares a single connection among threads. And you're right when you say that the documentation is not clear on that point. In fact, I wrote it with psycopg in mind (threadsafety=3D=3D2) and it is definitely *wrong* as far as MySQLdb is concerned; same for pgdb and pypgsql, btw --all but psycopg in fact ): However, as usual ;) the behaviour you reveal is a bug, not a feature. The framework should either: - automatically lock/unlock the shared connection --this solution would be equivalent to your ec.lock/unlock(), but the period of locking will be somehow smaller than when locking the ec - or use a different connection for each thread -- I expect this to=20 be longer to implement than the first solution. Could you please fill in a bug report (category: core) ? I'll try to have a look at it and propose a solution in the next two weeks, but I cannot promise since I've very little time at the moment. In the meantime, your solution is correct, and it's the only one. Cheers, -- S=E9bastien. |