def __sync_singlethreaded(self, list_accounts, profiledir): """Executed in singlethreaded mode only. :param accs: A list of accounts that should be synced """ for accountname in list_accounts: account = accounts.SyncableAccount(self.config, accountname) threading.currentThread().name = \ "Account sync %s" % account.getname() if not profiledir: account.syncrunner() # Profile mode. else: try: import cProfile as profile except ImportError: import profile prof = profile.Profile() try: prof = prof.runctx("account.syncrunner()", globals(), locals()) except SystemExit: pass from datetime import datetime dt = datetime.now().strftime('%Y%m%d%H%M%S') prof.dump_stats(os.path.join( profiledir, "%s_%s.prof" % (dt, account.getname())))
def __sync_singlethreaded(self, list_accounts): """Executed in singlethreaded mode only. :param accs: A list of accounts that should be synced """ for accountname in list_accounts: account = accounts.SyncableAccount(self.config, accountname) threading.currentThread().name = "Account sync %s" % account.name account.syncrunner()
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.