From: Angus Lees Date: Fri, 15 May 2015 07:54:18 +0000 (+1000) Subject: Use os._exit after forking X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f0decf6a4061be18999c87eab6ae152d9f75f99f;p=openstack-build%2Fneutron-build.git Use os._exit after forking As the docs point out(*), _exit should be used after a fork() to avoid both processes flushing filehandles, calling destructors with side effects, etc. This change does just that. (*) https://docs.python.org/2/library/os.html#os._exit Change-Id: I68da6283c44ab8857baf217ac1443bd17988257d --- diff --git a/neutron/agent/linux/daemon.py b/neutron/agent/linux/daemon.py index f180f5432..b4c7853b5 100644 --- a/neutron/agent/linux/daemon.py +++ b/neutron/agent/linux/daemon.py @@ -173,7 +173,7 @@ class Daemon(object): try: pid = os.fork() if pid > 0: - sys.exit(0) + os._exit(0) except OSError: LOG.exception(_LE('Fork failed')) sys.exit(1) diff --git a/neutron/tests/unit/agent/linux/test_daemon.py b/neutron/tests/unit/agent/linux/test_daemon.py index 4c01b6dbf..1ff0cc122 100644 --- a/neutron/tests/unit/agent/linux/test_daemon.py +++ b/neutron/tests/unit/agent/linux/test_daemon.py @@ -225,9 +225,9 @@ class TestDaemon(base.BaseTestCase): def test_fork_parent(self): self.os.fork.return_value = 1 - with testtools.ExpectedException(SystemExit): - d = daemon.Daemon('pidfile') - d._fork() + d = daemon.Daemon('pidfile') + d._fork() + self.os._exit.assert_called_once_with(mock.ANY) def test_fork_child(self): self.os.fork.return_value = 0