예제 #1
0
 def open(self, executable, port, output_length, console, timeout):
     self._lock('_open')
     if self.exe is not None:
         self._unlock('_open')
         raise error.general('tftp: already running')
     self._init()
     self.output_length = output_length
     self.console = console
     self.port = port
     self.exe = executable
     if self.console:
         self.console('tftp: exe: %s' % (executable))
     self.timeout = timeout[2]
     self.test_too_long = timeout[3]
     self.listener = threading.Thread(target=self._runner,
                                      name='tftp-listener')
     self.listener.start()
     step = 0.25
     period = timeout[0]
     seconds = timeout[1]
     output_len = self.output_length()
     while not self.finished and period > 0 and seconds > 0:
         if not self.running and self.caught:
             break
         current_length = self.output_length()
         if output_length != current_length:
             period = timeout[0]
         output_length = current_length
         if seconds < step:
             seconds = 0
         else:
             seconds -= step
         if period < step:
             step = period
             period = 0
         else:
             period -= step
         self._unlock('_open')
         time.sleep(step)
         self._lock('_open')
     if not self.finished:
         if period == 0:
             self._timeout()
         elif seconds == 0:
             self._test_too_long()
     caught = self.caught
     self._init()
     self._unlock('_open')
     if caught is not None:
         reraise.reraise(*caught)
예제 #2
0
 def open(self, executable, port, output_length, console, timeout):
     self._lock('_open')
     if self.exe is not None:
         self._unlock('_open')
         raise error.general('tftp: already running')
     self._init()
     self.output_length = output_length
     self.console = console
     self.port = port
     self.exe = executable
     self.timeout = timeout[1]
     self.listener = threading.Thread(target=self._runner,
                                      name='tftp-listener')
     self.listener.start()
     step = 0.5
     period = timeout[0]
     output_len = self.output_length()
     while not self.finished and period > 0:
         current_length = self.output_length()
         if output_length != current_length:
             period = timeout[0]
         output_length = current_length
         if period < step:
             period = 0
         else:
             period -= step
         self._unlock('_open')
         time.sleep(step)
         self._lock('_open')
     if not self.finished and period == 0:
         self._timeout()
     caught = self.caught
     self.caught = None
     self._unlock('_open')
     if caught is not None:
         reraise.reraise(*caught)
예제 #3
0
 def reraise(self):
     if self.result is not None:
         reraise.reraise(*self.result)