from nepi.util.tunchannel_impl import TunChannel
class HostLock(object):
+ # This class is used as a lock to prevent concurrency issues with more
+ # than one instance of netns running in the same machine. Both in
+ # different processes or different threads.
taken = False
processcond = threading.Condition()
self._condition = threading.Condition()
self._simulator_thread = threading.Thread(target = self._simulator_run,
args = [self._condition])
+ self._simulator_thread.setDaemon(True)
self._simulator_thread.start()
def stop(self, time = TIME_NOW):
element.Cleanup()
self._elements.clear()
if self.ns3:
- #self.ns3.Simulator.Stop()
- self._stop_simulation("0s")
- if self._simulator_thread:
- self._simulator_thread.join()
+ self.ns3.Simulator.Stop()
+ #self._stop_simulation("0s")
+ # 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()
else:
DEV_NULL = "/dev/null"
-
-
SHELL_SAFE = re.compile('^[-a-zA-Z0-9_=+:.,/]*$')
def shell_escape(s):
pid1 = os.fork()
if pid1 > 0:
os.close(w)
- os.read(r, 1)
+ while True:
+ try:
+ os.read(r, 1)
+ except OSError, e: # pragma: no cover
+ if e.errno == errno.EINTR:
+ continue
+ else:
+ raise
+ break
os.close(r)
# os.waitpid avoids leaving a <defunc> (zombie) process
st = os.waitpid(pid1, 0)[1]