How to use the offlineimap.threadutil.ExitNotifyThread function in offlineimap

To help you get started, we’ve selected a few offlineimap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OfflineIMAP / offlineimap / offlineimap / ui / Tk.py View on Github external
self.notdeleted = 1
        self.created = threading.Event()

        self.af = {}
        self.aflock = Lock()

        t = threadutil.ExitNotifyThread(target = self._runmainloop,
                                        name = "Tk Mainloop")
        t.setDaemon(1)
        t.start()

        self.created.wait()
        del self.created

        if doidlevac:
            t = threadutil.ExitNotifyThread(target = self.idlevacuum,
                                            name = "Tk idle vacuum")
            t.setDaemon(1)
            t.start()
github OfflineIMAP / offlineimap / offlineimap / init.py View on Github external
signal.signal(signal.SIGUSR2, sig_handler)
            signal.signal(signal.SIGABRT, sig_handler)
            signal.signal(signal.SIGTERM, sig_handler)
            signal.signal(signal.SIGINT, sig_handler)
            signal.signal(signal.SIGQUIT, sig_handler)

            # Various initializations that need to be performed:
            activeaccounts = self._get_activeaccounts(options)
            mbnames.init(self.config, self.ui, options.dryrun)

            if options.singlethreading:
                # Singlethreaded.
                self.__sync_singlethreaded(activeaccounts, options.profiledir)
            else:
                # Multithreaded.
                t = threadutil.ExitNotifyThread(
                    target=syncitall,
                    name='Sync Runner',
                    args=(activeaccounts, self.config,)
                    )
                # Special exit message for the monitor to stop looping.
                t.exit_message = threadutil.STOP_MONITOR
                t.start()
                threadutil.monitor()

            # All sync are done.
            mbnames.write()
            self.ui.terminate()
            return 0
        except (SystemExit):
            raise
        except Exception as e:
github OfflineIMAP / offlineimap / offlineimap / head / offlineimap / init.py View on Github external
threadutil.initInstanceLimit("ACCOUNTLIMIT", 1)
    else:
        threadutil.initInstanceLimit("ACCOUNTLIMIT",
                                     config.getdefaultint("general", "maxsyncaccounts", 1))

    for reposname in config.getsectionlist('Repository'):
        for instancename in ["FOLDER_" + reposname,
                             "MSGCOPY_" + reposname]:
            if '-1' in options:
                threadutil.initInstanceLimit(instancename, 1)
            else:
                threadutil.initInstanceLimit(instancename,
                                             config.getdefaultint('Repository ' + reposname, "maxconnections", 1))

    threadutil.initexitnotify()
    t = ExitNotifyThread(target=syncmaster.syncitall,
                         name='Sync Runner',
                         kwargs = {'accounts': syncaccounts,
                                   'config': config})
    t.setDaemon(1)
    t.start()
    try:
        threadutil.exitnotifymonitorloop(threadutil.threadexited)
    except SystemExit:
        raise
    except:
        ui.mainException()                  # Also expected to terminate.
github OfflineIMAP / offlineimap / offlineimap / init.py View on Github external
threadutil.initInstanceLimit("ACCOUNTLIMIT", 1)
        else:
            threadutil.initInstanceLimit("ACCOUNTLIMIT",
                                         config.getdefaultint("general", "maxsyncaccounts", 1))

        for reposname in config.getsectionlist('Repository'):
            for instancename in ["FOLDER_" + reposname,
                                 "MSGCOPY_" + reposname]:
                if options.has_key('-1'):
                    threadutil.initInstanceLimit(instancename, 1)
                else:
                    threadutil.initInstanceLimit(instancename,
                                                 config.getdefaultint('Repository ' + reposname, "maxconnections", 1))

        threadutil.initexitnotify()
        t = ExitNotifyThread(target=syncmaster.syncitall,
                             name='Sync Runner',
                             kwargs = {'accounts': syncaccounts,
                                       'config': config})
        t.setDaemon(1)
        t.start()
    except:
        ui.mainException()

    try:
        threadutil.exitnotifymonitorloop(threadutil.threadexited)
    except SystemExit:
        raise
    except:
        ui.mainException()                  # Also expected to terminate.
github OfflineIMAP / offlineimap / offlineimap / threadutil.py View on Github external
# Instance-limited threads
######################################################################

instancelimitedsems = {}
instancelimitedlock = Lock()

def initInstanceLimit(instancename, instancemax):
    """Initialize the instance-limited thread implementation to permit
    up to intancemax threads with the given instancename."""

    instancelimitedlock.acquire()
    if not instancename in instancelimitedsems:
        instancelimitedsems[instancename] = BoundedSemaphore(instancemax)
    instancelimitedlock.release()

class InstanceLimitedThread(ExitNotifyThread):
    def __init__(self, instancename, *args, **kwargs):
        self.instancename = instancename
        super(InstanceLimitedThread, self).__init__(*args, **kwargs)

    def start(self):
        instancelimitedsems[self.instancename].acquire()
        ExitNotifyThread.start(self)

    def run(self):
        try:
            ExitNotifyThread.run(self)
        finally:
            if instancelimitedsems and instancelimitedsems[self.instancename]:
                instancelimitedsems[self.instancename].release()
github OfflineIMAP / offlineimap / offlineimap / threadutil.py View on Github external
def run(self):
        global exitthreads
        try:
            if not ExitNotifyThread.profiledir: # normal case
                Thread.run(self)
            else:
                try:
                    import cProfile as profile
                except ImportError:
                    import profile
                prof = profile.Profile()
                try:
                    prof = prof.runctx("Thread.run(self)", globals(), locals())
                except SystemExit:
                    pass
                prof.dump_stats(os.path.join(ExitNotifyThread.profiledir,
                                "%s_%s.prof"% (self.ident, self.getName())))
        except Exception as e:
            # Thread exited with Exception, store it
            tb = traceback.format_exc()
            self.set_exit_exception(e, tb)

        if exitthreads:
            exitthreads.put(self, True)
github OfflineIMAP / offlineimap / offlineimap / threadutil.py View on Github external
def start(self):
        instancelimitedsems[self.instancename].acquire()
        ExitNotifyThread.start(self)
github OfflineIMAP / offlineimap / offlineimap / ui / Curses.py View on Github external
# lock the curses IO while fudging stuff
        self.ui.exec_locked(locked_display)

    def update(self, acc_win, x, y):
        """Update the xy position of the '.' (and possibly the aframe)."""

        self.window = acc_win
        self.y = y
        self.x = x
        self.display()

    def std_color(self):
        self.setcolor('black')


class InputHandler(ExitNotifyThread):
    """Listens for input via the curses interfaces"""

    #TODO, we need to use the ugly exitnotifythread (rather than simply
    #threading.Thread here, so exiting this thread via the callback
    #handler, kills off all parents too. Otherwise, they would simply
    #continue.
    def __init__(self, ui):
        super(InputHandler, self).__init__()
        self.char_handler = None
        self.ui = ui
        self.enabled = Event()
        # We will only parse input if we are enabled.
        self.inputlock = RLock()
        # denotes whether we should be handling the next char.
        self.start() #automatically start the thread
github OfflineIMAP / offlineimap / offlineimap / repository / IMAP.py View on Github external
def startkeepalive(self):
        keepalivetime = self.getkeepalive()
        if not keepalivetime: return
        self.kaevent = Event()
        self.kathread = ExitNotifyThread(target = self.imapserver.keepalive,
                                         name = "Keep alive " + self.getname(),
                                         args = (keepalivetime, self.kaevent))
        self.kathread.setDaemon(1)
        self.kathread.start()