diff --git a/tornado/ioloop.py b/tornado/ioloop.py index 6e3a6f1c..572b48c2 100644 --- a/tornado/ioloop.py +++ b/tornado/ioloop.py @@ -110,8 +110,8 @@ class IOLoop(object): self._waker_reader = os.fdopen(r, "r", 0) self._waker_writer = os.fdopen(w, "w", 0) else: - pipe = win32_support.Pipe() - r = pipe.reader_fd + self._waker_reader = self._waker_writer = win32_support.Pipe() + r = self._waker_writer.reader_fd self.add_handler(r, self._read_waker, self.READ) @classmethod diff --git a/tornado/test/test_ioloop.py b/tornado/test/test_ioloop.py new file mode 100644 index 00000000..1dd56ccb --- /dev/null +++ b/tornado/test/test_ioloop.py @@ -0,0 +1,40 @@ +# So we can run this file standalone from the test directory +import sys +sys.path.insert(0, '..') + +import unittest +import time + +import ioloop + + +class TestIOLoop(unittest.TestCase): + def setUp(self): + self.loop = ioloop.IOLoop() + + def tearDown(self): + pass + + def _callback(self): + self.called = True + self.loop.stop() + + def _schedule_callback(self): + self.loop.add_callback(self._callback) + # Scroll away the time so we can check if we woke up immediately + self._start_time = time.time() + self.called = False + + def test_add_callback(self): + self.loop.add_timeout(time.time(), self._schedule_callback) + self.loop.start() # Set some long poll timeout so we can check wakeup + self.assertAlmostEqual(time.time(), self._start_time, places=2) + self.assertTrue(self.called) + + +if __name__ == "__main__": + import logging + + logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(msecs)03d %(levelname)-8s %(name)-8s %(message)s', datefmt='%H:%M:%S') + + unittest.main() diff --git a/tornado/win32_support.py b/tornado/win32_support.py index 88cfc160..ee55d7e2 100644 --- a/tornado/win32_support.py +++ b/tornado/win32_support.py @@ -2,6 +2,7 @@ import ctypes import ctypes.wintypes import os import socket +import errno # See: http://msdn.microsoft.com/en-us/library/ms738573(VS.85).aspx @@ -94,7 +95,7 @@ class Pipe(object): if count >= 10: # I've never seen it go above 2 a.close() self.writer.close() - raise BindError("Cannot bind trigger!") + raise socket.error("Cannot bind trigger!") # Close `a` and try again. Note: I originally put a short # sleep() here, but it didn't appear to help or hurt. a.close()