Need advices for mysqldb connection best practice

Discussion in 'Python' started by Romaric DEFAUX, Jan 20, 2011.

  1. Hi all,


    I've a problem with a mysql connection. I run a client/server
    application. Every hour, clients contact the server, send datas, and the
    server updates the database. Everything works perfectly.
    But after a while, I get in trouble with my db connection. I've got the
    impression my server application "mix" the cursors...
    I've got this kind of strange errors in my log :
    Traceback (most recent call last):
    File "/usr/local/lib/audaxis/system_serverbox.py", line 519, in
    __update_in_db
    old_serverbox.load_from_db(cursor, self.__id)
    File "/usr/local/lib/audaxis/system_serverbox.py", line 131, in
    load_from_db
    self.__uuid = row['uuid']
    TypeError: 'NoneType' object is unsubscriptable

    Traceback (most recent call last):
    File "/usr/local/lib/audaxis/system_server.py", line 168, in process_data
    result += my_serverbox.save_website_list(cursor)
    File "/usr/local/lib/audaxis/system_serverbox.py", line 1197, in
    save_website_list
    old_serverbox.load_from_db(cursor, self.__id)
    File "/usr/local/lib/audaxis/system_serverbox.py", line 143, in
    load_from_db
    self.__load_disk_list_from_db(cursor)
    File "/usr/local/lib/audaxis/system_serverbox.py", line 203, in
    __load_disk_list_from_db
    my_disk.load_from_db(cursor, disk_id)
    File "/usr/local/lib/audaxis/system_disk.py", line 54, in load_from_db
    self.__fs = row['fs']
    KeyError: 'fs'

    Traceback (most recent call last):
    File "/usr/local/lib/audaxis/system_serverbox.py", line 521, in
    __update_in_db
    __uuid_host = self.is_virtual(cursor)
    File "/usr/local/lib/audaxis/system_serverbox.py", line 339, in
    is_virtual
    result = row['uuid']
    KeyError: 'uuid'

    and a lot of KeyError (at every update)

    The requests that produce these errors were working perfectly. And if I
    restart my server, everything is working fine again !

    Here's part of my code (I removed some parts):
    I create a db connection like this in my object server:
    def connect():
    con = MySQLdb.connect (host = "localhost", user = "myuser", passwd
    = "good_password", db = "my_db", cursorclass=DictCursor)
    con.ping(True) <- this normally activate auto-reconnection (or I
    did a mistake ?)
    con.cursor().execute('SET AUTOCOMMIT=1')
    return con

    self.__db_connection = connect()

    Then, each time a client connects :
    cursor = self.__db_connection.cursor()
    ...process the datas...
    cursor.close()

    So , I thought about some solutions :
    - restarting the server every sometimes (but it's the worst solution in
    my mind)
    - creating a connection (not only cursor) at each client connection (but
    I'm afraid it overloads the mysql server)
    - trying to find where I did a mistake, and correct the bug (that why
    I'm doing by writing this list :), or send me a link that could help me
    (before writing I googled for one hour and found nothing interresting in
    my case...)

    Thanks in advance for your advices !

    Romaric
    Romaric DEFAUX, Jan 20, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gildas Garcia

    need advices : intranet archecture design

    Gildas Garcia, Jul 4, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    355
    Gildas Garcia
    Jul 4, 2003
  2. Danny Ni

    Need advices on my codes

    Danny Ni, Nov 11, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    316
    Danny Ni
    Nov 11, 2004
  3. =?utf-8?B?5rW36aOO?=

    Need your advices

    =?utf-8?B?5rW36aOO?=, Apr 9, 2006, in forum: Java
    Replies:
    10
    Views:
    671
    Monique Y. Mudama
    Apr 17, 2006
  4. GrelEns
    Replies:
    1
    Views:
    263
    Paul Rubin
    Oct 23, 2003
  5. Joh
    Replies:
    2
    Views:
    311
    Lonnie Princehouse
    Jul 15, 2004
Loading...

Share This Page