From c843f34876703bb0e0ec75790f6c4d927d676ade Mon Sep 17 00:00:00 2001 From: Nicolas Sebrecht Date: Tue, 17 May 2016 02:38:35 +0200 Subject: [PATCH] threading: get rid of the syncaccount function Signed-off-by: Nicolas Sebrecht --- offlineimap/init.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/offlineimap/init.py b/offlineimap/init.py index 9a6e959..b04c9db 100644 --- a/offlineimap/init.py +++ b/offlineimap/init.py @@ -36,24 +36,22 @@ import traceback import collections -def syncaccount(config, accountname): - """Return a new running thread for this account.""" - - account = accounts.SyncableAccount(config, accountname) - thread = threadutil.InstanceLimitedThread(instancename = 'ACCOUNTLIMIT', - target = account.syncrunner, - name = "Account sync %s" % accountname) - thread.setDaemon(True) - thread.start() - return thread - -def syncitall(accounts, config): +def syncitall(list_accounts, config): """The target when in multithreading mode for running accounts threads.""" threads = threadutil.accountThreads() # The collection of accounts threads. - for accountname in accounts: + for accountname in list_accounts: # Start a new thread per account and store it in the collection. - threads.add(syncaccount(config, accountname)) + account = accounts.SyncableAccount(config, accountname) + thread = threadutil.InstanceLimitedThread( + instancename = 'ACCOUNTLIMIT', + target = account.syncrunner, + name = "Account sync %s"% accountname + ) + thread.setDaemon(True) + # The add() method expects a started thread. + thread.start() + threads.add(thread) # Wait for the threads to finish. threads.wait() # Blocks until all accounts are processed. @@ -410,9 +408,11 @@ class OfflineImap: self.__sync_singlethreaded(syncaccounts) else: # multithreaded - t = threadutil.ExitNotifyThread(target=syncitall, + t = threadutil.ExitNotifyThread( + target=syncitall, name='Sync Runner', - kwargs={'accounts': syncaccounts, 'config': self.config}) + args=(syncaccounts, self.config,) + ) # Special exit message for the monitor to stop looping. t.exit_message = threadutil.STOP_MONITOR t.start()