Fix for raising an exception;
Fix for waking loop; Added test
This commit is contained in:
parent
73fbe2843d
commit
3e1d57b2bd
|
@ -110,8 +110,8 @@ class IOLoop(object):
|
||||||
self._waker_reader = os.fdopen(r, "r", 0)
|
self._waker_reader = os.fdopen(r, "r", 0)
|
||||||
self._waker_writer = os.fdopen(w, "w", 0)
|
self._waker_writer = os.fdopen(w, "w", 0)
|
||||||
else:
|
else:
|
||||||
pipe = win32_support.Pipe()
|
self._waker_reader = self._waker_writer = win32_support.Pipe()
|
||||||
r = pipe.reader_fd
|
r = self._waker_writer.reader_fd
|
||||||
self.add_handler(r, self._read_waker, self.READ)
|
self.add_handler(r, self._read_waker, self.READ)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -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()
|
|
@ -2,6 +2,7 @@ import ctypes
|
||||||
import ctypes.wintypes
|
import ctypes.wintypes
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
|
import errno
|
||||||
|
|
||||||
|
|
||||||
# See: http://msdn.microsoft.com/en-us/library/ms738573(VS.85).aspx
|
# 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
|
if count >= 10: # I've never seen it go above 2
|
||||||
a.close()
|
a.close()
|
||||||
self.writer.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
|
# Close `a` and try again. Note: I originally put a short
|
||||||
# sleep() here, but it didn't appear to help or hurt.
|
# sleep() here, but it didn't appear to help or hurt.
|
||||||
a.close()
|
a.close()
|
||||||
|
|
Loading…
Reference in New Issue