Exemplo n.º 1
0
 class DummyTelnet():
     def __init__(self):
         self.Q = Queue()
         self.name = "dummytelnet"
     def putline(self, line):
         self.Q.put(line)
     def write(self, text):
         pass
     def readline(self):
         return self.Q.get_nowait()
Exemplo n.º 2
0
class Publisher(Thread):
    """ Publisher can be used when a thread is often spitting out results,
        and you want to process these results in gtk as soon as possible.
        While waiting for gdk access, results will be stored, and depending on
        the send policy, either the entire list, or only the last item will be
        sent as an argument to the function specified in the __init__ """

    SEND_LIST, SEND_LAST = range(2)

    def __init__(self, func, thread_namer, sendPolicy):
        Thread.__init__(self, name=get_threadname(thread_namer))
        self.daemon = True
        self.queue = Queue()
        self.func = func
        self.sendPolicy = sendPolicy

    def run(self):
        while True:
            v = self.queue.get()
            if v == self.StopNow:
                break

            glock.acquire()
            try:
                l = [v]
                while True:
                    try:
                        v = self.queue.get_nowait()
                    except Empty:
                        break
                    else:
                        if v == self.StopNow:
                            break
                        l.append(v)

                if self.sendPolicy == self.SEND_LIST:
                    self.func(l)
                elif self.sendPolicy == self.SEND_LAST:
                    self.func(l[-1])
            finally:
                glock.release()

            if v == self.StopNow:
                break

    def put(self, task):
        self.queue.put(task)

    def _del(self):
        self.queue.put(self.StopNow)

    class StopNow(Exception):
        pass
Exemplo n.º 3
0
class Publisher (Thread):
    """ Publisher can be used when a thread is often spitting out results,
        and you want to process these results in gtk as soon as possible.
        While waiting for gdk access, results will be stored, and depending on
        the send policy, either the entire list, or only the last item will be
        sent as an argument to the function specified in the __init__ """
    
    SEND_LIST, SEND_LAST = range(2)
    
    def __init__ (self, func, thread_namer, sendPolicy):
        Thread.__init__(self, name=get_threadname(thread_namer))      
        self.daemon = True
        self.queue = Queue()
        self.func = func
        self.sendPolicy = sendPolicy       
    
    def run (self):     
        while True:
            v = self.queue.get()            
            if v == self.StopNow:
                break
            
            glock.acquire()
            try:
                l = [v]               
                while True:
                    try:
                        v = self.queue.get_nowait()
                    except Empty:
                        break
                    else:
                        if v == self.StopNow:
                            break
                        l.append(v)
                
                if self.sendPolicy == self.SEND_LIST:
                    self.func(l)
                elif self.sendPolicy == self.SEND_LAST:
                    self.func(l[-1])
            finally:
                glock.release()

            if v == self.StopNow:
                break
    
    def put (self, task):
        self.queue.put(task)
    
    def _del (self):
        self.queue.put(self.StopNow)
    
    class StopNow(Exception): pass
Exemplo n.º 4
0
        class DummyTelnet():
            def __init__(self):
                self.Q = Queue()
                self.name = "dummytelnet"

            def putline(self, line):
                self.Q.put(line)

            def write(self, text):
                pass

            def readline(self):
                return self.Q.get_nowait()