3232from MLC .arduino .protocol import ProtocolConfig
3333from MLC .arduino .connection .serialconnection import SerialConnectionConfig
3434from MLC .arduino .boards import types
35+ import traceback
3536
3637logger = get_gui_logger ()
3738
@@ -66,6 +67,9 @@ def __init__(self, database, init_db=False):
6667 self .__next_individual_id = 1 if not self .__individuals else max (self .__individuals .keys ()) + 1
6768 self .__individuals_to_flush = {}
6869
70+ def close (self ):
71+ self ._conn .close ()
72+
6973 def __initialize_db (self ):
7074 cursor = self ._conn .cursor ()
7175
@@ -84,11 +88,19 @@ def __initialize_db(self):
8488 self ._conn .commit ()
8589
8690 def __get_db_connection (self , reopen_connection = False ):
87- # TODO: Workaround. SQLite throw an exception when a connection is used in different threads. To solve it,
88- # we create a new connection every time a new connection is delivered
91+ # TODO: Workaround. SQLite throw an exception when a connection is used
92+ # in different threads. To solve it, we create a new connection
93+ # every time a new connection is delivered
8994 if self ._database != SQLiteRepository .IN_MEMORY_DB :
90- self ._conn = sqlite3 .connect (self ._database )
95+ # Close the previous connection
96+ try :
97+ self ._conn .close ()
98+ except sqlite3 .ProgrammingError :
99+ # FIXME: There are open connections that cannot be closed for
100+ # the Thread bug. See what can be done
101+ pass
91102
103+ self ._conn = sqlite3 .connect (self ._database )
92104 return self ._conn
93105
94106 def __insert_individuals_pending (self , individual ):
0 commit comments