[PATCH 4/4] threading: get rid of the syncaccount function
Nicolas Sebrecht
nicolas.s-dev at laposte.net
Tue May 17 01:46:00 BST 2016
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev at laposte.net>
---
offlineimap/init.py | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/offlineimap/init.py b/offlineimap/init.py
index 9a6e959..68f6402 100644
--- a/offlineimap/init.py
+++ b/offlineimap/init.py
@@ -36,24 +36,23 @@ 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:
- # Start a new thread per account and store it in the collection.
- threads.add(syncaccount(config, accountname))
+ for accountname in list_accounts:
+ # Start a new thread per account and store it in the collection. The add
+ # method expects a started thread.
+ account = accounts.SyncableAccount(config, accountname)
+ thread = threadutil.InstanceLimitedThread(
+ instancename = 'ACCOUNTLIMIT',
+ target = account.syncrunner,
+ name = "Account sync %s"% accountname
+
+ )
+ thread.setDaemon(True)
+ thread.start()
+ threads.add(thread)
# Wait for the threads to finish.
threads.wait() # Blocks until all accounts are processed.
@@ -410,9 +409,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()
--
2.7.4
More information about the OfflineIMAP-project
mailing list