示例#1
0
文件: threads.py 项目: Mego/Karkat
    def dump(self):
        """
        Dumps the contents of the caller's queue, returns it, then terminates.
        """

        newq = Work()
        requeue = []
        with self.work._lock:
            # This blocks the queue.
            # The lock will be acquired after the queue feeds a task
            # to the caller, or the caller is still executing a task.
            lastarg = self.work.last
            while not self.work.empty():
                funct, args = self.work.get()
                if Callback.isThreadsafe(funct) or funct != lastarg:
                    newq.put((funct, args))
                else:
                    requeue.append((funct, args))
            for funct, args in requeue:
                # These functions aren't threadsafe, so we can't safely fork
                # off a queue with these tasks because we know that the
                # function is probably already executing.
                self.work.put((funct, args))
            self.terminate()
        return newq
示例#2
0
文件: threads.py 项目: Mego/Karkat
 def __init__(self, trigger, function):
     self.trigger = trigger
     self.module = inspect.getmodule(function)
     self.name = self.module.__name__ + "." + function.__qualname__
     self.funct = function
     if Callback.isInline(function):
         self.cbtype = self.INLINE
     elif Callback.isThreadsafe(function):
         self.cbtype = self.THREADSAFE
     elif Callback.isBackground(function):
         self.cbtype = self.BACKGROUND
     else:
         self.cbtype = self.GENERAL
示例#3
0
 def __init__(self, trigger, function):
     self.trigger = trigger
     self.module = inspect.getmodule(function)
     self.name = function.__qualname__
     if self.module:
         self.name = self.module.__name__ + "." + self.name
     self.funct = function
     if Callback.isInline(function):
         self.cbtype = self.INLINE
         self.__mutex__ = {function}
     elif Callback.isThreadsafe(function):
         self.cbtype = self.THREADSAFE
         self.__mutex__ = set()
     elif Callback.isBackground(function):
         self.cbtype = self.BACKGROUND
         self.__mutex__ = {function}
     else:
         self.cbtype = self.GENERAL
         if hasattr(function, '__mutex__'):
             self.__mutex__ = function.__mutex__
         else:
             self.__mutex__ = {function}
示例#4
0
 def __init__(self, trigger, function):
     self.trigger = trigger
     self.module = inspect.getmodule(function)
     self.name = function.__qualname__
     if self.module:
         self.name = self.module.__name__ + "." + self.name
     self.funct = function
     if Callback.isInline(function):
         self.cbtype = self.INLINE
         self.__mutex__ = {function}
     elif Callback.isThreadsafe(function):
         self.cbtype = self.THREADSAFE
         self.__mutex__ = set()
     elif Callback.isBackground(function):
         self.cbtype = self.BACKGROUND
         self.__mutex__ = {function}
     else:
         self.cbtype = self.GENERAL
         if hasattr(function, '__mutex__'):
             self.__mutex__ = function.__mutex__
         else:
             self.__mutex__ = {function}