Fixed concurrent DB access

This commit is contained in:
Stefano Marinelli 2023-10-21 10:49:50 +02:00
parent 98b14dbf8f
commit 19756f055b

View file

@ -113,13 +113,10 @@ class DatabaseHandler:
def close(self): def close(self):
self.connection.close() self.connection.close()
# Create a global database handler
db_handler = DatabaseHandler()
class EmailProcessor: class EmailProcessor:
def __init__(self, mail): def __init__(self, mail):
self.mail = mail self.mail = mail
self.db_handler = db_handler # Use the global db_handler self.db_handler = DatabaseHandler() # Create a new db_handler for each instance
def fetch_unseen_emails(self): def fetch_unseen_emails(self):
status, messages = self.mail.uid('search', None, "UNSEEN") status, messages = self.mail.uid('search', None, "UNSEEN")
@ -420,7 +417,6 @@ def multi_account_main():
handler.mail.logout() handler.mail.logout()
except: except:
pass pass
processor.db_handler.close()
if __name__ == "__main__": if __name__ == "__main__":
multi_account_main() multi_account_main()