use python locks instead of db locks for global lock
This commit is contained in:
parent
9d9f850753
commit
6a69bf512e
|
@ -17,6 +17,7 @@
|
|||
|
||||
import os
|
||||
import sys
|
||||
import threading
|
||||
import Options
|
||||
import string
|
||||
cl_options = string.join(sys.argv[1:])
|
||||
|
@ -116,11 +117,13 @@ class fpdb:
|
|||
def dia_create_del_database(self, widget, data=None):
|
||||
print "todo: implement dia_create_del_database"
|
||||
self.obtain_global_lock()
|
||||
self.release_global_lock()
|
||||
#end def dia_create_del_database
|
||||
|
||||
def dia_create_del_user(self, widget, data=None):
|
||||
print "todo: implement dia_create_del_user"
|
||||
self.obtain_global_lock()
|
||||
self.release_global_lock()
|
||||
#end def dia_create_del_user
|
||||
|
||||
def dia_database_stats(self, widget, data=None):
|
||||
|
@ -137,16 +140,19 @@ class fpdb:
|
|||
def dia_delete_db_parts(self, widget, data=None):
|
||||
print "todo: implement dia_delete_db_parts"
|
||||
self.obtain_global_lock()
|
||||
self.release_global_lock()
|
||||
#end def dia_delete_db_parts
|
||||
|
||||
def dia_edit_profile(self, widget=None, data=None, create_default=False, path=None):
|
||||
print "todo: implement dia_edit_profile"
|
||||
self.obtain_global_lock()
|
||||
self.release_global_lock()
|
||||
#end def dia_edit_profile
|
||||
|
||||
def dia_export_db(self, widget, data=None):
|
||||
print "todo: implement dia_export_db"
|
||||
self.obtain_global_lock()
|
||||
self.release_global_lock()
|
||||
#end def dia_export_db
|
||||
|
||||
def dia_get_db_root_credentials(self):
|
||||
|
@ -172,6 +178,7 @@ class fpdb:
|
|||
def dia_import_db(self, widget, data=None):
|
||||
print "todo: implement dia_import_db"
|
||||
self.obtain_global_lock()
|
||||
self.release_global_lock()
|
||||
#end def dia_import_db
|
||||
|
||||
def dia_licensing(self, widget, data=None):
|
||||
|
@ -180,7 +187,7 @@ class fpdb:
|
|||
|
||||
def dia_load_profile(self, widget, data=None):
|
||||
"""Dialogue to select a file to load a profile from"""
|
||||
if self.obtain_global_lock() == 0: # returns 0 if successful
|
||||
if self.obtain_global_lock(): # returns true if successful
|
||||
#try:
|
||||
# chooser = gtk.FileChooserDialog(title="Please select a profile file to load",
|
||||
# action=gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||
|
@ -195,15 +202,18 @@ class fpdb:
|
|||
# print 'User cancelled loading profile'
|
||||
#except:
|
||||
# pass
|
||||
self.load_profile()
|
||||
try:
|
||||
self.load_profile()
|
||||
except:
|
||||
pass
|
||||
self.release_global_lock()
|
||||
#end def dia_load_profile
|
||||
|
||||
def dia_recreate_tables(self, widget, data=None):
|
||||
"""Dialogue that asks user to confirm that he wants to delete and recreate the tables"""
|
||||
if self.obtain_global_lock() in (0,2): # returns 0 if successful, 2 if Hands table does not exist
|
||||
if self.obtain_global_lock(): # returns true if successful
|
||||
|
||||
lock_released = False
|
||||
#lock_released = False
|
||||
try:
|
||||
dia_confirm = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING,
|
||||
buttons=(gtk.BUTTONS_YES_NO), message_format="Confirm deleting and recreating tables")
|
||||
|
@ -214,27 +224,28 @@ class fpdb:
|
|||
response = dia_confirm.run()
|
||||
dia_confirm.destroy()
|
||||
if response == gtk.RESPONSE_YES:
|
||||
if self.db.fdb.backend == self.fdb_lock.fdb.MYSQL_INNODB:
|
||||
#if self.db.fdb.backend == self.fdb_lock.fdb.MYSQL_INNODB:
|
||||
# mysql requires locks on all tables or none - easier to release this lock
|
||||
# than lock all the other tables
|
||||
# ToDo: lock all other tables so that lock doesn't have to be released
|
||||
self.release_global_lock()
|
||||
lock_released = True
|
||||
self.db.fdb.recreate_tables()
|
||||
else:
|
||||
# self.release_global_lock()
|
||||
# lock_released = True
|
||||
self.db.fdb.recreate_tables()
|
||||
#else:
|
||||
# for other dbs use same connection as holds global lock
|
||||
self.fdb_lock.fdb.recreate_tables()
|
||||
# self.fdb_lock.fdb.recreate_tables()
|
||||
elif response == gtk.RESPONSE_NO:
|
||||
print 'User cancelled recreating tables'
|
||||
except:
|
||||
pass
|
||||
if not lock_released:
|
||||
self.release_global_lock()
|
||||
#if not lock_released:
|
||||
self.release_global_lock()
|
||||
#end def dia_recreate_tables
|
||||
|
||||
def dia_regression_test(self, widget, data=None):
|
||||
print "todo: implement dia_regression_test"
|
||||
self.obtain_global_lock()
|
||||
self.release_global_lock()
|
||||
#end def dia_regression_test
|
||||
|
||||
def dia_save_profile(self, widget, data=None):
|
||||
|
@ -353,6 +364,7 @@ class fpdb:
|
|||
"""Loads profile from the provided path name."""
|
||||
self.config = Configuration.Config(file=options.config, dbname=options.dbname)
|
||||
self.settings = {}
|
||||
self.settings['global_lock'] = self.lock
|
||||
if (os.sep=="/"):
|
||||
self.settings['os']="linuxmac"
|
||||
else:
|
||||
|
@ -405,10 +417,15 @@ class fpdb:
|
|||
#end def not_implemented
|
||||
|
||||
def obtain_global_lock(self):
|
||||
print "\nTaking global lock ..."
|
||||
self.fdb_lock = Database.Database(self.config, sql = self.sql)
|
||||
self.fdb_lock.do_connect(self.config)
|
||||
return self.fdb_lock.fdb.get_global_lock()
|
||||
ret = self.lock.acquire(False) # will return false if lock is already held
|
||||
if ret:
|
||||
print "\nGlobal lock taken ..."
|
||||
else:
|
||||
print "\nFailed to get global lock."
|
||||
return ret
|
||||
# need to release it later:
|
||||
# self.lock.release()
|
||||
|
||||
#end def obtain_global_lock
|
||||
|
||||
def quit(self, widget, data=None):
|
||||
|
@ -419,8 +436,7 @@ class fpdb:
|
|||
#end def quit_cliecked
|
||||
|
||||
def release_global_lock(self):
|
||||
self.fdb_lock.fdb.db.rollback()
|
||||
self.fdb_lock.fdb.disconnect()
|
||||
self.lock.release()
|
||||
print "Global lock released.\n"
|
||||
#end def release_global_lock
|
||||
|
||||
|
@ -487,6 +503,7 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt")
|
|||
|
||||
def __init__(self):
|
||||
self.threads = []
|
||||
self.lock = threading.Lock()
|
||||
self.db = None
|
||||
self.status_bar = None
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user