From e6f834e617df4b8719db72ad512bce2e034a6b08 Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Sat, 14 Nov 2009 10:56:02 +0200 Subject: [PATCH 01/10] Catch missing table (key) in hud_dict This may be the cause of hud and/or main app hanging when import is stopped --- pyfpdb/HUD_main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index e9fb40fb..0b53f200 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -234,7 +234,12 @@ class HUD_main(object): self.db_connection.init_hud_stat_vars( self.hud_dict[temp_key].hud_params['hud_days'] , self.hud_dict[temp_key].hud_params['h_hud_days']) stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_dict[temp_key].hud_params, self.hero_ids[site_id]) - self.hud_dict[temp_key].stat_dict = stat_dict + try: + self.hud_dict[temp_key].stat_dict = stat_dict + except KeyError: # HUD instance has been killed off, key is stale + sys.stderr.write('hud_dict[%s] was not found\n' % temp_key) + sys.stderr.write('will not send hand\n') + return cards = self.db_connection.get_cards(new_hand_id) comm_cards = self.db_connection.get_common_cards(new_hand_id) if comm_cards != {}: # stud! From 52d8578841032cf0ff0e215a36889d6b826bcb5f Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Tue, 24 Nov 2009 10:57:03 +0200 Subject: [PATCH 02/10] Try to fix HUD hangs --- pyfpdb/HUD_main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index e936602a..04f46287 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -219,6 +219,8 @@ class HUD_main(object): except KeyError: # HUD instance has been killed off, key is stale sys.stderr.write('hud_dict[%s] was not found\n' % temp_key) sys.stderr.write('will not send hand\n') + # Unlocks table, copied from end of function + self.db_connection.connection.rollback() return cards = self.db_connection.get_cards(new_hand_id) comm_cards = self.db_connection.get_common_cards(new_hand_id) From 92918df8c5148d06d2bae795d779b2aa8c2f66ae Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Wed, 25 Nov 2009 00:12:07 +0200 Subject: [PATCH 03/10] Attempt to catch the final race Table attributes are pulled from database but the table window itself may have disappeared. The search parameters no longer match because there is no window title to match against, so some attributes are not set at all. --- pyfpdb/HUD_main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index f57ab587..89436c52 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -252,7 +252,13 @@ class HUD_main(object): else: tablewindow.max = max tablewindow.site = site_name - self.create_HUD(new_hand_id, tablewindow, temp_key, max, poker_game, type, stat_dict, cards) + # Test that the table window still exists + try: + _n = tablewindow.name + self.create_HUD(new_hand_id, tablewindow, temp_key, max, poker_game, type, stat_dict, cards) + except AttributeError: + sys.stderr.write('Table "%s" no longer exists\n', table_name) + self.db_connection.connection.rollback() if __name__== "__main__": From 752e50ad4c75ed358609134903136a84cbd5ea80 Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Wed, 25 Nov 2009 07:26:26 +0200 Subject: [PATCH 04/10] Better test Built-in function hasattr() deals with and hides the exception --- pyfpdb/HUD_main.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 89436c52..5b2cc085 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -253,10 +253,9 @@ class HUD_main(object): tablewindow.max = max tablewindow.site = site_name # Test that the table window still exists - try: - _n = tablewindow.name + if hasattr(tablewindow, 'name'): self.create_HUD(new_hand_id, tablewindow, temp_key, max, poker_game, type, stat_dict, cards) - except AttributeError: + else: sys.stderr.write('Table "%s" no longer exists\n', table_name) self.db_connection.connection.rollback() From 9c591da893cce73e66c82d617471949f4aa71be7 Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Wed, 25 Nov 2009 11:10:34 +0200 Subject: [PATCH 05/10] Saner exit for thread-unsafe code It can't be right that we return from threads_enter() before releasing the global lock. Exit works properly for failure (try-finally). --- pyfpdb/HUD_main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 5b2cc085..30844887 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -122,6 +122,7 @@ class HUD_main(object): m.update_gui(new_hand_id) self.hud_dict[table_name].update(new_hand_id, self.config) self.hud_dict[table_name].reposition_windows() + gtk.gdk.threads_leave() return False finally: gtk.gdk.threads_leave() From a7163f5f8c355d64ba76b2f843b23946ba755731 Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Wed, 25 Nov 2009 14:42:17 +0200 Subject: [PATCH 06/10] Move return value outside try-finally block The return value is for Glib/GTK event loop, so it should be after try-finally sequence. The value needs to be returned every time and we really like to have threads_enter()/threads_leave() to be invoked in pairs. --- pyfpdb/HUD_main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 30844887..453a8e82 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -122,10 +122,9 @@ class HUD_main(object): m.update_gui(new_hand_id) self.hud_dict[table_name].update(new_hand_id, self.config) self.hud_dict[table_name].reposition_windows() - gtk.gdk.threads_leave() - return False finally: gtk.gdk.threads_leave() + return False self.hud_dict[table_name] = Hud.Hud(self, table, max, poker_game, self.config, self.db_connection) self.hud_dict[table_name].table_name = table_name From c7342e4b0f2eec6144de8d1a8b022dfb91cc3494 Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Wed, 25 Nov 2009 15:31:45 +0200 Subject: [PATCH 07/10] Test the correct attribute When testing for Tables.Table validity, we actually care about the 'number' attribute, because that gets passed around on create_HUD() --- pyfpdb/HUD_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 453a8e82..27d7eea0 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -253,7 +253,7 @@ class HUD_main(object): tablewindow.max = max tablewindow.site = site_name # Test that the table window still exists - if hasattr(tablewindow, 'name'): + if hasattr(tablewindow, 'number'): self.create_HUD(new_hand_id, tablewindow, temp_key, max, poker_game, type, stat_dict, cards) else: sys.stderr.write('Table "%s" no longer exists\n', table_name) From df6d9a0a56b575cc375173571aaa6351e531953c Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Thu, 26 Nov 2009 23:07:58 +0200 Subject: [PATCH 08/10] Fix missing checks before .set_active() Some validity tests were still missing. Also, typofix: self.cbFl -> self.cbFL --- pyfpdb/Filters.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pyfpdb/Filters.py b/pyfpdb/Filters.py index 5beef90f..c74d5579 100644 --- a/pyfpdb/Filters.py +++ b/pyfpdb/Filters.py @@ -312,8 +312,8 @@ class Filters(threading.Thread): self.cbAllLimits.set_active(False) if not self.limits[limit]: if limit.isdigit(): - if self.cbFl is not None: - self.cbFl.set_active(False) + if self.cbFL is not None: + self.cbFL.set_active(False) else: if self.cbNL is not None: self.cbNL.set_active(False) @@ -329,8 +329,10 @@ class Filters(threading.Thread): if self.limits[limit]: for cb in self.cbLimits.values(): cb.set_active(False) - self.cbNL.set_active(False) - self.cbFL.set_active(False) + if self.cbNL is not None: + self.cbNL.set_active(False) + if self.cbFL is not None: + self.cbFL.set_active(False) elif limit == "fl": if not self.limits[limit]: # only toggle all fl limits off if they are all currently on From 6dec7f38f3988a276b28548b4b9d96c962a56f3b Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Fri, 27 Nov 2009 22:21:45 +0200 Subject: [PATCH 09/10] Fix a stupid syntax error Use python's format-string syntax. --- pyfpdb/HUD_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 6f63a2b5..39096065 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -260,7 +260,7 @@ class HUD_main(object): if hasattr(tablewindow, 'number'): self.create_HUD(new_hand_id, tablewindow, temp_key, max, poker_game, type, stat_dict, cards) else: - sys.stderr.write('Table "%s" no longer exists\n', table_name) + sys.stderr.write('Table "%s" no longer exists\n' % table_name) self.db_connection.connection.rollback() From 2f742e371be64964fe9499824901c71f0509601c Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Sat, 28 Nov 2009 10:59:44 +0200 Subject: [PATCH 10/10] Use wider try-except block The 'temp_key' table name in hud_dict can vanish between DB roundtrips. Enclose all three lines within try-block. --- pyfpdb/HUD_main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 39096065..4f7e8845 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -215,10 +215,10 @@ class HUD_main(object): # Update an existing HUD if temp_key in self.hud_dict: # get stats using hud's specific params and get cards - self.db_connection.init_hud_stat_vars( self.hud_dict[temp_key].hud_params['hud_days'] - , self.hud_dict[temp_key].hud_params['h_hud_days']) - stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_dict[temp_key].hud_params, self.hero_ids[site_id]) try: + self.db_connection.init_hud_stat_vars( self.hud_dict[temp_key].hud_params['hud_days'] + , self.hud_dict[temp_key].hud_params['h_hud_days']) + stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_dict[temp_key].hud_params, self.hero_ids[site_id]) self.hud_dict[temp_key].stat_dict = stat_dict except KeyError: # HUD instance has been killed off, key is stale sys.stderr.write('hud_dict[%s] was not found\n' % temp_key)