Browse Source

Merge branch 'warning-non-flushed-mysql-cache' into test-v3

develop
Jonathan Golder 8 years ago
parent
commit
9113a40704
  1. 17
      mysqlred.py

17
mysqlred.py

@ -31,6 +31,8 @@ try:
except ImportError:
import MySQLdb as mysqldb
import atexit
from pywikibot import config
import jogobot
@ -72,7 +74,10 @@ class MysqlRed:
user=type( self ).db_username,
passwd=type( self ).db_password,
db=type( self ).db_name )
# Register callback for warnig if exit with cached db write querys
atexit.register( type(self).warn_if_not_flushed )
def __del__( self ):
"""
Before deleting class, close connection to MySQL-DB
@ -108,6 +113,16 @@ class MysqlRed:
if cls._cached_insert_data or cls._cached_update_data:
cls.connection.commit()
@classmethod
def warn_if_not_flushed(cls):
"""
Outputs a warning if there are db write querys cached and not flushed
before exiting programm!
"""
if cls._cached_update_data or cls._cached_insert_data:
jogobot.output( "Cached Database write querys not flushed!!! " +
"Data loss is possible!", "WARNING" )
class MysqlRedPage( MysqlRed ):
"""

Loading…
Cancel
Save