Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > MySQLdb reconnect

Reply
Thread Tools

MySQLdb reconnect

 
 
Damjan
Guest
Posts: n/a
 
      06-22-2005
Does MySQLdb automatically reconnect if the connection to the database is
broken?

I'm asking this since I have a longrunning Python precess that is connected
to Mysql-4.1.11, and I execute "set names utf8" when I connect to it.

But after running a day the results from the python program were displayed
as if the "set names utf8" was not executed i.e. I got question marks where
utf-8 cyrillics should've appeared. After restarting the Python program
everything was ok, just as when I first started it.

The long running Python process is actually a scgi quixote web application.


--
damjan
 
Reply With Quote
 
 
 
 
Eloff
Guest
Posts: n/a
 
      06-22-2005
I don't beleive that it does. You can however call ping() on the
connection which should attempt an automatic reconnection.

See the docs for mysql_ping:

http://dev.mysql.com/doc/mysql/en/mysql-ping.html

I've never tested that, but I have a need for it also so let me know if
it works or not.

-Dan

 
Reply With Quote
 
 
 
 
Damjan
Guest
Posts: n/a
 
      06-29-2005
> Does MySQLdb automatically reconnect if the connection to the database is
> broken?


It seems so.

> I'm asking this since I have a longrunning Python precess that is
> connected to Mysql-4.1.11, and I execute "set names utf8" when I connect
> to it.
>
> But after running a day the results from the python program were displayed
> as if the "set names utf8" was not executed i.e. I got question marks
> where utf-8 cyrillics should've appeared. After restarting the Python
> program everything was ok, just as when I first started it.


This is the sollution I've come to:

try:
# This will fail on MySQL < 4.1
db = MySQLdb.connect(godot.dbhost, godot.dbuser, godot.dbpass,
godot.dbname, use_unicode=1, init_command="set names utf8")
except MySQLdb.OperationalError:
db = MySQLdb.connect(godot.dbhost, godot.dbuser, godot.dbpass,
godot.dbname, use_unicode=1)
db.charset = 'utf8'


--
damjan
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adhoc network wont reconnect unless computers restarted. =?Utf-8?B?cGxhc3Rpa2Fh?= Wireless Networking 0 07-28-2005 08:06 AM
Westell 327W sees SSID but won't reconnect cansubaykan@netscape.net Wireless Networking 5 07-26-2005 08:59 PM
no automatic reauthentication/reconnect Lars P. Wireless Networking 0 02-01-2005 02:18 PM
Can't reconnect to tablet pc after system upgrade MJW Wireless Networking 0 12-26-2004 10:13 PM
Looking for hotfix - 828940 Wireless Client Cannot Reconnect to a Wireless Access Point Chris Wireless Networking 1 07-07-2004 07:51 PM



Advertisments