Ejemplo n.º 1
0
 def _runWithCallback(self, callback, errback, func, args, kwargs):
     try:
         result = apply(func, args, kwargs)
     except Exception, e:
         task.schedule(errback, e)
Ejemplo n.º 2
0
 def _runWithCallback(self, callback, errback, func, args, kwargs):
     try:
         result = apply(func, args, kwargs)
     except Exception, e:
         task.schedule(errback, e)
Ejemplo n.º 3
0
        tpool = ThreadDispatcher()
        main.addShutdown(tpool.stop)

    """
    
    def __init__(self, *args, **kwargs):
        apply(threadpool.ThreadPool.__init__, (self,) + args, kwargs)
        self._callbacks = []
    
    def _runWithCallback(self, callback, errback, func, args, kwargs):
        try:
            result = apply(func, args, kwargs)
        except Exception, e:
            task.schedule(errback, e)
        else:
            task.schedule(callback, result)
    
    def dispatchWithCallback(self, owner, callback, errback, func, *args, **kw):
        """Dispatch a function, returning the result to a callback function.
        
        The callback function will be called in the main event loop thread.
        """
        self.dispatchApply(owner, callback, errback, func, args, kw)

    def dispatchApply(self, owner, callback, errback, func, args, kw):
        self.dispatch(owner, self._runWithCallback, callback, errback, func, args, kw)


theDispatcher = ThreadDispatcher(0)

def dispatchApply(callback, errback, func, args, kw):
Ejemplo n.º 4
0
        from twisted.internet import threadtask
        tpool = ThreadDispatcher()
        main.addShutdown(tpool.stop)

    """
    def __init__(self, *args, **kwargs):
        apply(threadpool.ThreadPool.__init__, (self, ) + args, kwargs)
        self._callbacks = []

    def _runWithCallback(self, callback, errback, func, args, kwargs):
        try:
            result = apply(func, args, kwargs)
        except Exception, e:
            task.schedule(errback, e)
        else:
            task.schedule(callback, result)

    def dispatchWithCallback(self, owner, callback, errback, func, *args,
                             **kw):
        """Dispatch a function, returning the result to a callback function.
        
        The callback function will be called in the main event loop thread.
        """
        self.dispatchApply(owner, callback, errback, func, args, kw)

    def dispatchApply(self, owner, callback, errback, func, args, kw):
        self.dispatch(owner, self._runWithCallback, callback, errback, func,
                      args, kw)


theDispatcher = ThreadDispatcher(0)