|  | @@ -17,6 +17,7 @@ from celery.bin.worker import worker, main as worker_main
 | 
	
		
			
				|  |  |  from celery.exceptions import (
 | 
	
		
			
				|  |  |      ImproperlyConfigured, WorkerShutdown, WorkerTerminate,
 | 
	
		
			
				|  |  |  )
 | 
	
		
			
				|  |  | +from celery.platforms import EX_FAILURE, EX_OK
 | 
	
		
			
				|  |  |  from celery.utils.log import ensure_process_aware_logger
 | 
	
		
			
				|  |  |  from celery.worker import state
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -490,8 +491,8 @@ class test_signal_handlers(WorkerAppCase):
 | 
	
		
			
				|  |  |          worker = self._Worker()
 | 
	
		
			
				|  |  |          handlers = self.psig(cd.install_worker_int_handler, worker)
 | 
	
		
			
				|  |  |          next_handlers = {}
 | 
	
		
			
				|  |  | -        state.should_stop = False
 | 
	
		
			
				|  |  | -        state.should_terminate = False
 | 
	
		
			
				|  |  | +        state.should_stop = None
 | 
	
		
			
				|  |  | +        state.should_terminate = None
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          class Signals(platforms.Signals):
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -504,15 +505,17 @@ class test_signal_handlers(WorkerAppCase):
 | 
	
		
			
				|  |  |              try:
 | 
	
		
			
				|  |  |                  handlers['SIGINT']('SIGINT', object())
 | 
	
		
			
				|  |  |                  self.assertTrue(state.should_stop)
 | 
	
		
			
				|  |  | +                self.assertEqual(state.should_stop, EX_FAILURE)
 | 
	
		
			
				|  |  |              finally:
 | 
	
		
			
				|  |  |                  platforms.signals = p
 | 
	
		
			
				|  |  | -                state.should_stop = False
 | 
	
		
			
				|  |  | +                state.should_stop = None
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              try:
 | 
	
		
			
				|  |  |                  next_handlers['SIGINT']('SIGINT', object())
 | 
	
		
			
				|  |  |                  self.assertTrue(state.should_terminate)
 | 
	
		
			
				|  |  | +                self.assertEqual(state.should_terminate, EX_FAILURE)
 | 
	
		
			
				|  |  |              finally:
 | 
	
		
			
				|  |  | -                state.should_terminate = False
 | 
	
		
			
				|  |  | +                state.should_terminate = None
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          with patch('celery.apps.worker.active_thread_count') as c:
 | 
	
		
			
				|  |  |              c.return_value = 1
 | 
	
	
		
			
				|  | @@ -543,7 +546,7 @@ class test_signal_handlers(WorkerAppCase):
 | 
	
		
			
				|  |  |                  self.assertTrue(state.should_stop)
 | 
	
		
			
				|  |  |              finally:
 | 
	
		
			
				|  |  |                  process.name = name
 | 
	
		
			
				|  |  | -                state.should_stop = False
 | 
	
		
			
				|  |  | +                state.should_stop = None
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          with patch('celery.apps.worker.active_thread_count') as c:
 | 
	
		
			
				|  |  |              c.return_value = 1
 | 
	
	
		
			
				|  | @@ -554,7 +557,7 @@ class test_signal_handlers(WorkerAppCase):
 | 
	
		
			
				|  |  |                      handlers['SIGINT']('SIGINT', object())
 | 
	
		
			
				|  |  |              finally:
 | 
	
		
			
				|  |  |                  process.name = name
 | 
	
		
			
				|  |  | -                state.should_stop = False
 | 
	
		
			
				|  |  | +                state.should_stop = None
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @disable_stdouts
 | 
	
		
			
				|  |  |      def test_install_HUP_not_supported_handler(self):
 | 
	
	
		
			
				|  | @@ -580,14 +583,17 @@ class test_signal_handlers(WorkerAppCase):
 | 
	
		
			
				|  |  |                      handlers['SIGQUIT']('SIGQUIT', object())
 | 
	
		
			
				|  |  |                      self.assertTrue(state.should_terminate)
 | 
	
		
			
				|  |  |                  finally:
 | 
	
		
			
				|  |  | -                    state.should_terminate = False
 | 
	
		
			
				|  |  | +                    state.should_terminate = None
 | 
	
		
			
				|  |  |              with patch('celery.apps.worker.active_thread_count') as c:
 | 
	
		
			
				|  |  |                  c.return_value = 1
 | 
	
		
			
				|  |  |                  worker = self._Worker()
 | 
	
		
			
				|  |  |                  handlers = self.psig(
 | 
	
		
			
				|  |  |                      cd.install_worker_term_hard_handler, worker)
 | 
	
		
			
				|  |  | -                with self.assertRaises(WorkerTerminate):
 | 
	
		
			
				|  |  | -                    handlers['SIGQUIT']('SIGQUIT', object())
 | 
	
		
			
				|  |  | +                try:
 | 
	
		
			
				|  |  | +                    with self.assertRaises(WorkerTerminate):
 | 
	
		
			
				|  |  | +                        handlers['SIGQUIT']('SIGQUIT', object())
 | 
	
		
			
				|  |  | +                finally:
 | 
	
		
			
				|  |  | +                    state.should_terminate = None
 | 
	
		
			
				|  |  |          finally:
 | 
	
		
			
				|  |  |              process.name = name
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -599,9 +605,9 @@ class test_signal_handlers(WorkerAppCase):
 | 
	
		
			
				|  |  |              handlers = self.psig(cd.install_worker_term_handler, worker)
 | 
	
		
			
				|  |  |              try:
 | 
	
		
			
				|  |  |                  handlers['SIGTERM']('SIGTERM', object())
 | 
	
		
			
				|  |  | -                self.assertTrue(state.should_stop)
 | 
	
		
			
				|  |  | +                self.assertEqual(state.should_stop, EX_OK)
 | 
	
		
			
				|  |  |              finally:
 | 
	
		
			
				|  |  | -                state.should_stop = False
 | 
	
		
			
				|  |  | +                state.should_stop = None
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @disable_stdouts
 | 
	
		
			
				|  |  |      def test_worker_term_handler_when_single_thread(self):
 | 
	
	
		
			
				|  | @@ -613,7 +619,7 @@ class test_signal_handlers(WorkerAppCase):
 | 
	
		
			
				|  |  |                  with self.assertRaises(WorkerShutdown):
 | 
	
		
			
				|  |  |                      handlers['SIGTERM']('SIGTERM', object())
 | 
	
		
			
				|  |  |              finally:
 | 
	
		
			
				|  |  | -                state.should_stop = False
 | 
	
		
			
				|  |  | +                state.should_stop = None
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @patch('sys.__stderr__')
 | 
	
		
			
				|  |  |      @skip_if_pypy
 | 
	
	
		
			
				|  | @@ -637,7 +643,7 @@ class test_signal_handlers(WorkerAppCase):
 | 
	
		
			
				|  |  |                  worker = self._Worker()
 | 
	
		
			
				|  |  |                  handlers = self.psig(cd.install_worker_term_handler, worker)
 | 
	
		
			
				|  |  |                  handlers['SIGTERM']('SIGTERM', object())
 | 
	
		
			
				|  |  | -                self.assertTrue(state.should_stop)
 | 
	
		
			
				|  |  | +                self.assertEqual(state.should_stop, EX_OK)
 | 
	
		
			
				|  |  |              with patch('celery.apps.worker.active_thread_count') as c:
 | 
	
		
			
				|  |  |                  c.return_value = 1
 | 
	
		
			
				|  |  |                  worker = self._Worker()
 | 
	
	
		
			
				|  | @@ -646,7 +652,7 @@ class test_signal_handlers(WorkerAppCase):
 | 
	
		
			
				|  |  |                      handlers['SIGTERM']('SIGTERM', object())
 | 
	
		
			
				|  |  |          finally:
 | 
	
		
			
				|  |  |              process.name = name
 | 
	
		
			
				|  |  | -            state.should_stop = False
 | 
	
		
			
				|  |  | +            state.should_stop = None
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @disable_stdouts
 | 
	
		
			
				|  |  |      @patch('celery.platforms.close_open_fds')
 | 
	
	
		
			
				|  | @@ -665,14 +671,14 @@ class test_signal_handlers(WorkerAppCase):
 | 
	
		
			
				|  |  |              worker = self._Worker()
 | 
	
		
			
				|  |  |              handlers = self.psig(cd.install_worker_restart_handler, worker)
 | 
	
		
			
				|  |  |              handlers['SIGHUP']('SIGHUP', object())
 | 
	
		
			
				|  |  | -            self.assertTrue(state.should_stop)
 | 
	
		
			
				|  |  | +            self.assertEqual(state.should_stop, EX_OK)
 | 
	
		
			
				|  |  |              self.assertTrue(register.called)
 | 
	
		
			
				|  |  |              callback = register.call_args[0][0]
 | 
	
		
			
				|  |  |              callback()
 | 
	
		
			
				|  |  |              self.assertTrue(argv)
 | 
	
		
			
				|  |  |          finally:
 | 
	
		
			
				|  |  |              os.execv = execv
 | 
	
		
			
				|  |  | -            state.should_stop = False
 | 
	
		
			
				|  |  | +            state.should_stop = None
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @disable_stdouts
 | 
	
		
			
				|  |  |      def test_worker_term_hard_handler_when_threaded(self):
 | 
	
	
		
			
				|  | @@ -684,7 +690,7 @@ class test_signal_handlers(WorkerAppCase):
 | 
	
		
			
				|  |  |                  handlers['SIGQUIT']('SIGQUIT', object())
 | 
	
		
			
				|  |  |                  self.assertTrue(state.should_terminate)
 | 
	
		
			
				|  |  |              finally:
 | 
	
		
			
				|  |  | -                state.should_terminate = False
 | 
	
		
			
				|  |  | +                state.should_terminate = None
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @disable_stdouts
 | 
	
		
			
				|  |  |      def test_worker_term_hard_handler_when_single_threaded(self):
 |