From f0decf6a4061be18999c87eab6ae152d9f75f99f Mon Sep 17 00:00:00 2001 From: Angus Lees Date: Fri, 15 May 2015 17:54:18 +1000 Subject: [PATCH] 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 --- neutron/agent/linux/daemon.py | 2 +- neutron/tests/unit/agent/linux/test_daemon.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) 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 -- 2.45.2