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
try:
pid = os.fork()
if pid > 0:
- sys.exit(0)
+ os._exit(0)
except OSError:
LOG.exception(_LE('Fork failed'))
sys.exit(1)
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