コード例 #1
0
ファイル: threadtask.py プロジェクト: lhl/songclub
 def _runWithCallback(self, callback, errback, func, args, kwargs):
     try:
         result = apply(func, args, kwargs)
     except Exception, e:
         task.schedule(errback, e)
コード例 #2
0
 def _runWithCallback(self, callback, errback, func, args, kwargs):
     try:
         result = apply(func, args, kwargs)
     except Exception, e:
         task.schedule(errback, e)
コード例 #3
0
ファイル: threadtask.py プロジェクト: lhl/songclub
        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):
コード例 #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)