Browse Source

Merge "Skips signal handling on Windows"

Zuul 7 months ago
parent
commit
c51d20f56c
2 changed files with 15 additions and 1 deletions
  1. 3
    1
      oslo_service/service.py
  2. 12
    0
      oslo_service/tests/test_service.py

+ 3
- 1
oslo_service/service.py View File

@@ -28,6 +28,7 @@ import io
28 28
 import logging
29 29
 import os
30 30
 import random
31
+import select
31 32
 import signal
32 33
 import six
33 34
 import sys
@@ -203,7 +204,8 @@ class SignalHandler(object):
203 204
         For Python 3.5 and later, deal with the changes in PEP 475 that prevent
204 205
         a signal from interrupting eventlet's call to poll() or sleep().
205 206
         """
206
-        self.__force_interrupt_on_signal = sys.version_info >= (3, 5)
207
+        self.__force_interrupt_on_signal = (sys.version_info >= (3, 5) and
208
+                                            hasattr(select, 'poll'))
207 209
 
208 210
         if self.__force_interrupt_on_signal:
209 211
             try:

+ 12
- 0
oslo_service/tests/test_service.py View File

@@ -477,6 +477,18 @@ class ProcessLauncherTest(base.ServiceBaseTestCase):
477 477
             m.assert_called_once_with(signal.SIGTERM, 'test')
478 478
         signal_handler.clear()
479 479
 
480
+    @mock.patch('sys.version_info', (3, 5))
481
+    @mock.patch.object(service, 'select', spec=[])
482
+    def test_setup_signal_interruption_no_select_poll(self, mock_select):
483
+        # NOTE(claudiub): SignalHandler is a singleton, which means that it
484
+        # might already be initialized. We need to clear to clear the cache
485
+        # in order to prevent race conditions between tests.
486
+        service.SignalHandler.__class__._instances.clear()
487
+        signal_handler = service.SignalHandler()
488
+        self.addCleanup(service.SignalHandler.__class__._instances.clear)
489
+        self.assertFalse(
490
+            signal_handler._SignalHandler__force_interrupt_on_signal)
491
+
480 492
     @mock.patch('signal.alarm')
481 493
     @mock.patch("os.kill")
482 494
     @mock.patch("oslo_service.service.ProcessLauncher.stop")

Loading…
Cancel
Save