[asterisk-commits] russell: testsuite/asterisk/trunk r778 - /asterisk/trunk/lib/python/asterisk/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Aug 24 15:44:42 CDT 2010
Author: russell
Date: Tue Aug 24 15:44:40 2010
New Revision: 778
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=778
Log:
Be a lot more paranoid when shutting down Asterisk.
If Asterisk is not cleanly shut down (which results in Asterisk running exit()),
then the code coverage data will not be written out to the gcda files. Only
revert back to killing off Asterisk using signals if it really seems necessary.
Modified:
asterisk/trunk/lib/python/asterisk/asterisk.py
Modified: asterisk/trunk/lib/python/asterisk/asterisk.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/asterisk.py?view=diff&rev=778&r1=777&r2=778
==============================================================================
--- asterisk/trunk/lib/python/asterisk/asterisk.py (original)
+++ asterisk/trunk/lib/python/asterisk/asterisk.py Tue Aug 24 15:44:40 2010
@@ -124,18 +124,54 @@
Example Usage:
asterisk.stop()
"""
+ #
+ # Start by asking to stop gracefully.
+ #
if self.ast_version < AsteriskVersion("1.6.0"):
self.cli_exec("stop gracefully")
else:
self.cli_exec("core stop gracefully")
+ for i in xrange(5):
+ time.sleep(1.0)
+ if self.process.poll() is not None:
+ return self.process.returncode
+
+ #
+ # If the graceful shutdown did not complete within 5 seconds, ask
+ # Asterisk to stop right now.
+ #
+ if self.ast_version < AsteriskVersion("1.6.0"):
+ self.cli_exec("stop now")
+ else:
+ self.cli_exec("core stop now")
+ for i in xrange(5):
+ time.sleep(1.0)
+ if self.process.poll() is not None:
+ return self.process.returncode
+
+ #
+ # If even a "stop now" didn't do the trick, fall back to sending
+ # signals to the process. First, send a SIGTERM. If it _STILL_ hasn't
+ # gone away after another 5 seconds, send SIGKILL.
+ #
try:
os.kill(self.process.pid, signal.SIGTERM)
- time.sleep(5.0)
- if not self.process.poll():
- os.kill(self.process.pid, signal.SIGKILL)
+ for i in xrange(5):
+ time.sleep(1.0)
+ if self.process.poll() is not None:
+ return self.process.returncode
+ os.kill(self.process.pid, signal.SIGKILL)
except OSError:
+ # Probably that we sent a signal to a process that was already
+ # dead. Just ignore it.
pass
+
+ #
+ # We have done everything we can do at this point. Wait for the
+ # process to exit.
+ #
self.process.wait()
+
return self.process.returncode
def install_configs(self, cfg_path):
More information about the asterisk-commits
mailing list