From: Claudio-Daniel Freire Date: Wed, 15 Jun 2011 09:47:41 +0000 (+0200) Subject: Shutdown fix: wait for the simulator to stop running before dereferencing elements. X-Git-Tag: nepi_v2_1~30 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=8041ac20cd4f60e27d1d7d156f13d2f7dab86ff5;p=nepi.git Shutdown fix: wait for the simulator to stop running before dereferencing elements. NS3 isn't thread-safe, so destroying elements (which could happen when dereferenced) while the simulator is running could be disastruous --- diff --git a/src/nepi/testbeds/ns3/execute.py b/src/nepi/testbeds/ns3/execute.py index 5f9bb72f..1fdd4154 100644 --- a/src/nepi/testbeds/ns3/execute.py +++ b/src/nepi/testbeds/ns3/execute.py @@ -129,14 +129,24 @@ class TestbedController(testbed_impl.TestbedController): if isinstance(element, self.LOCAL_TYPES): # graceful shutdown of locally-implemented objects element.Cleanup() - self._elements.clear() if self.ns3: self.ns3.Simulator.Stop() + + # Wait for it to stop, with a 30s timeout + for i in xrange(300): + if self.ns3.Simulator.isFinished(): + break + time.sleep(0.1) #self._stop_simulation("0s") - # TODO!!!! SHOULD WAIT UNTIL THE THREAD FINISHES - # if self._simulator_thread: - # self._simulator_thread.join() + + self._elements.clear() + + if self.ns3: + # TODO!!!! SHOULD WAIT UNTIL THE THREAD FINISHES + # if self._simulator_thread: + # self._simulator_thread.join() self.ns3.Simulator.Destroy() + self._ns3 = None sys.stdout.flush() sys.stderr.flush()