diff options
-rw-r--r-- | tulip/events_test.py | 6 | ||||
-rw-r--r-- | tulip/selectors.py | 10 | ||||
-rw-r--r-- | tulip/tasks_test.py | 4 |
3 files changed, 16 insertions, 4 deletions
diff --git a/tulip/events_test.py b/tulip/events_test.py index c2dd5e0..acb15ba 100644 --- a/tulip/events_test.py +++ b/tulip/events_test.py @@ -6,6 +6,7 @@ import os import select import signal import socket +import sys import threading import time import unittest @@ -326,6 +327,7 @@ class EventLoopTestsMixin: conn.close() listener.close() + @unittest.skipUnless(hasattr(signal, 'SIGKILL'), 'No SIGKILL') def testAddSignalHandler(self): caught = 0 def my_handler(): @@ -359,6 +361,7 @@ class EventLoopTestsMixin: # Removing again returns False. self.assertFalse(el.remove_signal_handler(signal.SIGINT)) + @unittest.skipIf(sys.platform == 'win32', 'Unix only') def testCancelSignalHandler(self): # Cancelling the handler should remove it (eventually). caught = 0 @@ -372,6 +375,7 @@ class EventLoopTestsMixin: el.run_once() self.assertEqual(caught, 0) + @unittest.skipUnless(hasattr(signal, 'SIGALRM'), 'No SIGALRM') def testSignalHandlingWhileSelecting(self): # Test with a signal actually arriving during a select() call. caught = 0 @@ -413,7 +417,7 @@ class EventLoopTestsMixin: host, port = sock.getsockname() self.assertEqual(host, '0.0.0.0') client = socket.socket() - client.connect((host, port)) + client.connect(('127.0.0.1', port)) client.send(b'xxx') el.run_once() # This is quite mysterious, but necessary. el.run_once() diff --git a/tulip/selectors.py b/tulip/selectors.py index 08762f8..158876c 100644 --- a/tulip/selectors.py +++ b/tulip/selectors.py @@ -4,6 +4,7 @@ This module supports asynchronous I/O on multiple file descriptors. """ import logging +import sys from select import * @@ -216,7 +217,7 @@ class SelectSelector(_BaseSelector): def select(self, timeout=None): try: - r, w, _ = select(self._readers, self._writers, [], timeout) + r, w, _ = self._select(self._readers, self._writers, [], timeout) except InterruptedError: # A signal arrived. Don't die, just return no events. return [] @@ -234,6 +235,13 @@ class SelectSelector(_BaseSelector): ready.append((key.fileobj, events, key.data)) return ready + if sys.platform == 'win32': + def _select(self, r, w, _, timeout=None): + r, w, x = select(r, w, w, timeout) + return r, w + x, [] + else: + from select import select as _select + if 'poll' in globals(): diff --git a/tulip/tasks_test.py b/tulip/tasks_test.py index c99cb8f..a738145 100644 --- a/tulip/tasks_test.py +++ b/tulip/tasks_test.py @@ -134,7 +134,7 @@ class TaskTests(unittest.TestCase): res = self.event_loop.run_until_complete(tasks.Task(foo())) t1 = time.monotonic() self.assertTrue(t1-t0 >= 0.1) - self.assertTrue(t1-t0 <= 0.12) + self.assertTrue(t1-t0 <= 0.13) def testAsCompleted(self): @tasks.coroutine @@ -226,7 +226,7 @@ class TaskTests(unittest.TestCase): doer = doit() self.assertEqual(self.event_loop.run_until_complete(doer), 'cancelled') t1 = time.monotonic() - self.assertTrue(0.09 <= t1-t0 <= 0.11, (t1-t0, sleepfut, doer)) + self.assertTrue(0.09 <= t1-t0 <= 0.13, (t1-t0, sleepfut, doer)) if __name__ == '__main__': |