Merge "Have timeouts in fullstack raise exceptions"

This commit is contained in:
Jenkins
2016-09-12 11:13:48 +00:00
committed by Gerrit Code Review
2 changed files with 7 additions and 6 deletions

View File

@@ -90,11 +90,11 @@ class DFDaemon(object):
self.thread = None
self.is_daemonize = False
def wait(self, timeout=None):
def wait(self, timeout=None, exception=None):
if not self.is_daemonize or not self.thread:
return False
if timeout and timeout > 0:
timeout_obj = eventlet.Timeout(timeout)
timeout_obj = eventlet.Timeout(timeout, exception)
try:
self.thread.wait()
except greenlet.GreenletExit:

View File

@@ -449,14 +449,15 @@ class Policy(object):
:param timeout: After this many seconds, throw an exception
:type timeout: Number
"""
exception = Exception('Timeout')
if timeout is not None:
entry_time = time.time()
for thread in self.threads:
thread.wait(timeout)
thread.wait(timeout, exception)
if timeout is not None:
timeout -= time.time() - entry_time
if timeout <= 0:
raise Exception('Timeout')
raise exception
def stop(self):
"""Stop all threads. Prepare for a new simulation."""
@@ -858,8 +859,8 @@ class PortThread(object):
if self.thread_id != threading.current_thread().ident:
self.daemon.stop()
def wait(self, timeout=None):
self.daemon.wait(timeout)
def wait(self, timeout=None, exception=None):
self.daemon.wait(timeout, exception)
def run(self):
"""Continuously read from the tap device, and send received data to the