Don't use signal.alarm on python2
This commit is contained in:
@@ -147,7 +147,13 @@ class Service(object):
|
|||||||
def _terminate(self):
|
def _terminate(self):
|
||||||
signal.signal(signal.SIGTERM, signal.SIG_IGN)
|
signal.signal(signal.SIGTERM, signal.SIG_IGN)
|
||||||
if self.graceful_shutdown_timeout > 0:
|
if self.graceful_shutdown_timeout > 0:
|
||||||
|
# NOTE(sileht): signal.alarm doesn't work well on python2
|
||||||
|
# use a threading timer instead
|
||||||
|
if sys.version_info[0] == 3:
|
||||||
signal.alarm(self.graceful_shutdown_timeout)
|
signal.alarm(self.graceful_shutdown_timeout)
|
||||||
|
else:
|
||||||
|
threading.Timer(self.graceful_shutdown_timeout,
|
||||||
|
self._graceful_shutdown_timeout_cb).start()
|
||||||
with _exit_on_exception():
|
with _exit_on_exception():
|
||||||
self.terminate()
|
self.terminate()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
@@ -157,7 +163,7 @@ class Service(object):
|
|||||||
'graceful exiting of service %s' % self._title)
|
'graceful exiting of service %s' % self._title)
|
||||||
self._terminate()
|
self._terminate()
|
||||||
|
|
||||||
def _graceful_shutdown_timeout_cb(self, signum, frame):
|
def _graceful_shutdown_timeout_cb(self, *args, **kwargs):
|
||||||
LOG.info('Graceful shutdown timeout (%d) exceeded, exiting %s now.' %
|
LOG.info('Graceful shutdown timeout (%d) exceeded, exiting %s now.' %
|
||||||
(self.graceful_shutdown_timeout, self._title))
|
(self.graceful_shutdown_timeout, self._title))
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
|
|||||||
@@ -209,9 +209,6 @@ class TestCotyledon(Base):
|
|||||||
class TestBuggyCotyledon(Base):
|
class TestBuggyCotyledon(Base):
|
||||||
name = "buggy_app"
|
name = "buggy_app"
|
||||||
|
|
||||||
@unittest.skipIf(sys.version_info[0] != 3,
|
|
||||||
"Buggy on py27, time.sleep returns before alarm callback "
|
|
||||||
"is called")
|
|
||||||
def test_graceful_timeout_term(self):
|
def test_graceful_timeout_term(self):
|
||||||
lines = self.get_lines(1)
|
lines = self.get_lines(1)
|
||||||
childpid = self.get_pid(lines[0])
|
childpid = self.get_pid(lines[0])
|
||||||
@@ -231,9 +228,6 @@ class TestBuggyCotyledon(Base):
|
|||||||
b'DEBUG:cotyledon:Shutdown finish'
|
b'DEBUG:cotyledon:Shutdown finish'
|
||||||
], lines[-3:])
|
], lines[-3:])
|
||||||
|
|
||||||
@unittest.skipIf(sys.version_info[0] != 3,
|
|
||||||
"Buggy on py27, time.sleep returns before alarm callback "
|
|
||||||
"is called")
|
|
||||||
def test_graceful_timeout_kill(self):
|
def test_graceful_timeout_kill(self):
|
||||||
lines = self.get_lines(1)
|
lines = self.get_lines(1)
|
||||||
childpid = self.get_pid(lines[0])
|
childpid = self.get_pid(lines[0])
|
||||||
|
|||||||
Reference in New Issue
Block a user