From cb9e2cb6e7dce51a1aa59749b9251b8a8c0cf4c2 Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Wed, 25 Nov 2009 20:31:01 +0200 Subject: [PATCH] Try to fix two HUD main hangs The main HUD process can hang due to unhandled exceptions, which occurred in two separate situations: 1. Table window is closed and HUD instance killed before auto-importer knows about it 2. Sometimes the threading can jam These changes attempt to counter the effect of race-conditions. The dictionary key (table name) is properly tested at the beginning of update/create block, *but* there are two short round-trips to database before the key is used. While these occur, the HUD instance can vanish and thus get its key removed from the dictionary. Also, when Tables.Table() is created, it will be populated on-demand, and have child attributes only when such are found from the system. The new table code pulls in data from actual windows. Again, there is a query involved and while it runs, the table may have vanished. This ended up as an error in this call: foo = gtk.gdk.window_foreign_new(table.number) The object 'table' is valid (not None) but it has been populated only after actual table window was killed. Therefore it may not have .number attribute, which raised an AttributeError. Now the presence of table.number attribute is tested before the object can be sent to create_HUD(). --- pyfpdb/HUD_main.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 7965f0b5..27d7eea0 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -122,9 +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() - 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 @@ -214,7 +214,14 @@ 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') + # 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) if comm_cards != {}: # stud! @@ -245,7 +252,12 @@ 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 + 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) + self.db_connection.connection.rollback() if __name__== "__main__":