Exemple #1
0
 def __init__(self, threadpool_threadcount, cb=None, exc_cb=None):
     _threadname = "Hoptoad%s-%d" % (self.__class__.__name__, os.getpid())
     threading.Thread.__init__(self, name=_threadname)
     self.threads = threadpool_threadcount
     self.daemon = True  # daemon thread... important!
     self.callback = cb
     self.exc_callback = exc_cb or _exception_handler
     self.pool = ThreadPool(self.threads)
     self.start()
Exemple #2
0
 def __init__(self, threadpool_threadcount, cb=None, exc_cb=None):
     _threadname = "Hoptoad%s-%d" % (self.__class__.__name__, os.getpid())
     threading.Thread.__init__(self, name=_threadname)
     self.threads = threadpool_threadcount
     self.daemon = True # daemon thread... important!
     self.callback = cb
     self.exc_callback = exc_cb or _exception_handler
     self.pool = ThreadPool(self.threads)
     self.start()
Exemple #3
0
class ThreadedNotifier(threading.Thread):
    """A daemon thread that spawns a threadpool of worker threads.
    
    Waits for queue additions through the enqueue method.
    """
    def __init__(self, threadpool_threadcount, cb=None, exc_cb=None):
        _threadname = "Hoptoad%s-%d" % (self.__class__.__name__, os.getpid())
        threading.Thread.__init__(self, name=_threadname)
        self.threads = threadpool_threadcount
        self.daemon = True # daemon thread... important!
        self.callback = cb
        self.exc_callback = exc_cb or _exception_handler
        self.pool = ThreadPool(self.threads)
        self.start()
    
    def enqueue(self, payload, timeout):
        request = WorkRequest(
            htv2.report,
            args=(payload, timeout),
            callback=self.callback,
            exc_callback=self.exc_callback
        )
        
        # Put the request into the queue where the detached 'run' method will
        # poll its queue every 0.5 seconds and start working.
        self.pool.putRequest(request)
    
    def run(self):
        """Actively poll the queue for requests and process them."""
        while True:
            try:
                time.sleep(0.5) # TODO: configure for tuning
                self.pool.poll()
            except KeyboardInterrupt:
                logger.info("* Interrupted!")
                break
            except NoResultsPending:
                pass
Exemple #4
0
class ThreadedNotifier(threading.Thread):
    """A daemon thread that spawns a threadpool of worker threads.

    Waits for queue additions through the enqueue method.
    """
    def __init__(self, threadpool_threadcount, cb=None, exc_cb=None):
        _threadname = "Hoptoad%s-%d" % (self.__class__.__name__, os.getpid())
        threading.Thread.__init__(self, name=_threadname)
        self.threads = threadpool_threadcount
        self.daemon = True  # daemon thread... important!
        self.callback = cb
        self.exc_callback = exc_cb or _exception_handler
        self.pool = ThreadPool(self.threads)
        self.start()

    def enqueue(self, payload, timeout):
        request = WorkRequest(htv2.report,
                              args=(payload, timeout),
                              callback=self.callback,
                              exc_callback=self.exc_callback)

        # Put the request into the queue where the detached 'run' method will
        # poll its queue every 0.5 seconds and start working.
        self.pool.putRequest(request)

    def run(self):
        """Actively poll the queue for requests and process them."""
        while True:
            try:
                time.sleep(0.5)  # TODO: configure for tuning
                self.pool.poll()
            except KeyboardInterrupt:
                logger.info("* Interrupted!")
                break
            except NoResultsPending:
                pass