def wrapper(*args, **kwargs):
            result = []
            # create new args for _new_func, because we want to get the func return val to result list
            new_kwargs = {
                'oldfunc': func,
                'result': result,
                'oldfunc_args': args,
                'oldfunc_kwargs': kwargs
            }

            thd = KThread(target=_new_func, args=(), kwargs=new_kwargs)
            thd.start()
            thd.join(seconds)
            alive = thd.isAlive()
            thd.kill()  # kill the child thread

            if alive:
                try:
                    raise Timeout('request timeout')
                finally:
                    return ''
            else:
                if result:
                    return result[0]
                else:
                    return ''
 def get(self, timeout=None):
     self._set.wait(timeout)
     if self._set.isSet():
         if self._error != None:
             raise self.exception(self._error)
         return self.value
     else:
         raise Timeout()
Exemple #3
0
 def handler(self, signum, frame):
     """
     Timeout occur.
     """
     if self.callback is None:
         raise Timeout()
     else:
         self.callback()
Exemple #4
0
 def matchPattern(self):    
     
     packetRegexMatch = None
     
     timeout = time.time() + self.timeout
     
     while (packetRegexMatch is None):
         
         justRead = self.serialDevice.read(5)
         
         if (time.time() > timeout):
             raise Timeout("No pattern matched in %f seconds, aborting" % (time.time() - timeout + self.timeout))
         
         self.currentReadBuffer = "%s%s" % (self.currentReadBuffer, justRead)
         
         packetRegexMatch = self.pattern.match(self.currentReadBuffer)
                 
         
     
     self.currentReadBuffer = self.currentReadBuffer[packetRegexMatch.end():]
     
     return packetRegexMatch
Exemple #5
0
 def check_flow_control(self):
   if self._flow_control:
     self._flow_control_wait_condition.wait(self._flow_control_wait_failure)
   if self._flow_control:
     raise Timeout("Unable to send message for " + str(self._flow_control_wait_failure) + " seconds due to broker enforced flow control")