Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for num, uid in enumerate(copylist):
# bail out on CTRL-C or SIGTERM
if offlineimap.accounts.Account.abort_NOW_signal.is_set():
break
if uid > 0 and dstfolder.uidexists(uid):
# dst has message with that UID already, only update status
flags = self.getmessageflags(uid)
rtime = self.getmessagetime(uid)
statusfolder.savemessage(uid, None, flags, rtime)
continue
self.ui.copyingmessage(uid, num+1, num_to_copy, self, dstfolder)
# exceptions are caught in copymessageto()
if self.suggeststhreads() and not globals.options.singlethreading:
self.waitforthread()
thread = threadutil.InstanceLimitedThread(\
self.getcopyinstancelimit(),
target = self.copymessageto,
name = "Copy message from %s:%s" % (self.repository, self),
args = (uid, dstfolder, statusfolder))
thread.start()
threads.append(thread)
else:
self.copymessageto(uid, dstfolder, statusfolder,
register = 0)
for thread in threads:
thread.join()
# Execute new mail hook if we have new mail
if self.have_newmail:
if self.newmail_hook != None:
self.newmail_hook();
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 list_accounts:
# Start a new thread per account and store it in the collection.
account = accounts.SyncableAccount(config, accountname)
thread = threadutil.InstanceLimitedThread(
ACCOUNT_LIMITED_THREAD_NAME,
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.
def sync(self):
# We don't need an account lock because syncitall() goes through
# each account once, then waits for all to finish.
try:
remoterepos = self.remoterepos
localrepos = self.localrepos
statusrepos = self.statusrepos
self.ui.syncfolders(remoterepos, localrepos)
remoterepos.syncfoldersto(localrepos)
folderthreads = []
for remotefolder in remoterepos.getfolders():
thread = InstanceLimitedThread(\
instancename = 'FOLDER_' + self.remoterepos.getname(),
target = syncfolder,
name = "Folder sync %s[%s]" % \
(self.name, remotefolder.getvisiblename()),
args = (self.name, remoterepos, remotefolder, localrepos,
statusrepos))
thread.setDaemon(1)
thread.start()
folderthreads.append(thread)
threadutil.threadsreset(folderthreads)
mbnames.write()
localrepos.holdordropconnections()
remoterepos.holdordropconnections()
finally:
pass
def __init__(self, instancename, *args, **kwargs):
self.instancename = instancename
super(InstanceLimitedThread, self).__init__(*args, **kwargs)
def syncaccount(threads, config, accountname):
account = SyncableAccount(config, accountname)
thread = InstanceLimitedThread(instancename = 'ACCOUNTLIMIT',
target = account.syncrunner,
name = "Account sync %s" % accountname)
thread.setDaemon(1)
thread.start()
threads.add(thread)
def syncaccount(config, accountname):
"""Return a new running thread for this account."""
account = SyncableAccount(config, accountname)
thread = InstanceLimitedThread(instancename = 'ACCOUNTLIMIT',
target = account.syncrunner,
name = "Account sync %s" % accountname)
thread.setDaemon(True)
thread.start()
return thread
def syncaccount(threads, config, accountname):
account = SyncableAccount(config, accountname)
thread = InstanceLimitedThread(instancename = 'ACCOUNTLIMIT',
target = account.syncrunner,
name = "Account sync %s" % accountname)
thread.setDaemon(1)
thread.start()
threads.add(thread)
else:
quick = False
try:
remoterepos = self.remoterepos
localrepos = self.localrepos
statusrepos = self.statusrepos
self.ui.syncfolders(remoterepos, localrepos)
remoterepos.syncfoldersto(localrepos, [statusrepos])
siglistener.addfolders(remoterepos.getfolders(), bool(self.refreshperiod), quick)
while True:
folderthreads = []
for remotefolder, quick in siglistener.queuedfolders():
thread = InstanceLimitedThread(\
instancename = 'FOLDER_' + self.remoterepos.getname(),
target = syncfolder,
name = "Folder sync %s[%s]" % \
(self.name, remotefolder.getvisiblename()),
args = (self.name, remoterepos, remotefolder, localrepos,
statusrepos, quick))
thread.setDaemon(1)
thread.start()
folderthreads.append(thread)
threadutil.threadsreset(folderthreads)
if siglistener.clearfolders():
break
mbnames.write()
localrepos.forgetfolders()
remoterepos.forgetfolders()
localrepos.holdordropconnections()