From 69a24eb84beb60902686a03e88533c0b625f7a9b Mon Sep 17 00:00:00 2001 From: Christophe Monniez Date: Tue, 28 Aug 2018 15:12:01 +0200 Subject: [PATCH] [FIX] tests: close Chrome and shutdown on SIGXCPU When Odoo receive a SIGXCPU (CPU time limit reached), it shuts down immediately. If a headless Chrome is running, it stays alive after the Odoo shutdown. With this commit, the signal is intercepeted and the Chrome browser is properly closed before shutting down the Odoo server. --- odoo/tests/common.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/odoo/tests/common.py b/odoo/tests/common.py index a282aa21e44..b87a42519eb 100644 --- a/odoo/tests/common.py +++ b/odoo/tests/common.py @@ -17,6 +17,7 @@ import platform import re import requests import shutil +import signal import subprocess import tempfile import threading @@ -426,6 +427,16 @@ class ChromeBrowser(): self._websocket_send('Runtime.enable') self._logger.info('Chrome headless enable page notifications') self._websocket_send('Page.enable') + self.sigxcpu_handler = None + if os.name == 'posix': + self.sigxcpu_handler = signal.getsignal(signal.SIGXCPU) + signal.signal(signal.SIGXCPU, self.signal_handler) + + def signal_handler(self, sig, frame): + if sig == signal.SIGXCPU: + _logger.info('CPU time limit reached, stopping Chrome and shutting down') + self.stop() + os._exit(0) def stop(self): if self.chrome_process is not None: @@ -438,6 +449,9 @@ class ChromeBrowser(): if self.user_data_dir and os.path.isdir(self.user_data_dir) and self.user_data_dir != '/': self._logger.info('Removing chrome user profile "%s"', self.user_data_dir) shutil.rmtree(self.user_data_dir) + # Restore previous signal handler + if self.sigxcpu_handler and os.name == 'posix': + signal.signal(signal.SIGXCPU, self.sigxcpu_handler) @property def executable(self):