Python tornado.ioloop.PollIOLoop() Examples

The following are 13 code examples of tornado.ioloop.PollIOLoop(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tornado.ioloop , or try the search function .
Example #1
Source File: ioloop_test.py    From tornado-zh with MIT License 5 votes vote down vote up
def test_remove_timeout_cleanup(self):
        # Add and remove enough callbacks to trigger cleanup.
        # Not a very thorough test, but it ensures that the cleanup code
        # gets executed and doesn't blow up.  This test is only really useful
        # on PollIOLoop subclasses, but it should run silently on any
        # implementation.
        for i in range(2000):
            timeout = self.io_loop.add_timeout(self.io_loop.time() + 3600,
                                               lambda: None)
            self.io_loop.remove_timeout(timeout)
        # HACK: wait two IOLoop iterations for the GC to happen.
        self.io_loop.add_callback(lambda: self.io_loop.add_callback(self.stop))
        self.wait() 
Example #2
Source File: ioloop_test.py    From tornado-zh with MIT License 5 votes vote down vote up
def test_remove_timeout_cleanup(self):
        # Add and remove enough callbacks to trigger cleanup.
        # Not a very thorough test, but it ensures that the cleanup code
        # gets executed and doesn't blow up.  This test is only really useful
        # on PollIOLoop subclasses, but it should run silently on any
        # implementation.
        for i in range(2000):
            timeout = self.io_loop.add_timeout(self.io_loop.time() + 3600,
                                               lambda: None)
            self.io_loop.remove_timeout(timeout)
        # HACK: wait two IOLoop iterations for the GC to happen.
        self.io_loop.add_callback(lambda: self.io_loop.add_callback(self.stop))
        self.wait() 
Example #3
Source File: ioloop_test.py    From teleport with Apache License 2.0 5 votes vote down vote up
def test_remove_timeout_cleanup(self):
        # Add and remove enough callbacks to trigger cleanup.
        # Not a very thorough test, but it ensures that the cleanup code
        # gets executed and doesn't blow up.  This test is only really useful
        # on PollIOLoop subclasses, but it should run silently on any
        # implementation.
        for i in range(2000):
            timeout = self.io_loop.add_timeout(self.io_loop.time() + 3600,
                                               lambda: None)
            self.io_loop.remove_timeout(timeout)
        # HACK: wait two IOLoop iterations for the GC to happen.
        self.io_loop.add_callback(lambda: self.io_loop.add_callback(self.stop))
        self.wait() 
Example #4
Source File: ioloop_test.py    From teleport with Apache License 2.0 5 votes vote down vote up
def test_timeout_with_arguments(self):
        # This tests that all the timeout methods pass through *args correctly.
        results = []
        self.io_loop.add_timeout(self.io_loop.time(), results.append, 1)
        self.io_loop.add_timeout(datetime.timedelta(seconds=0),
                                 results.append, 2)
        self.io_loop.call_at(self.io_loop.time(), results.append, 3)
        self.io_loop.call_later(0, results.append, 4)
        self.io_loop.call_later(0, self.stop)
        self.wait()
        # The asyncio event loop does not guarantee the order of these
        # callbacks, but PollIOLoop does.
        self.assertEqual(sorted(results), [1, 2, 3, 4]) 
Example #5
Source File: ioloop_test.py    From teleport with Apache License 2.0 5 votes vote down vote up
def run_python(self, *statements):
        statements = [
            'from tornado.ioloop import IOLoop, PollIOLoop',
            'classname = lambda x: x.__class__.__name__',
        ] + list(statements)
        args = [sys.executable, '-c', '; '.join(statements)]
        return native_str(subprocess.check_output(args)).strip() 
Example #6
Source File: ioloop_test.py    From teleport with Apache License 2.0 5 votes vote down vote up
def test_default(self):
        if asyncio is not None:
            # When asyncio is available, it is used by default.
            cls = self.run_python('print(classname(IOLoop.current()))')
            self.assertEqual(cls, 'AsyncIOMainLoop')
            cls = self.run_python('print(classname(IOLoop()))')
            self.assertEqual(cls, 'AsyncIOLoop')
        else:
            # Otherwise, the default is a subclass of PollIOLoop
            is_poll = self.run_python(
                'print(isinstance(IOLoop.current(), PollIOLoop))')
            self.assertEqual(is_poll, 'True') 
Example #7
Source File: twisted_test.py    From teleport with Apache License 2.0 5 votes vote down vote up
def initialize(self, **kwargs):
            self.real_io_loop = PollIOLoop(make_current=False)  # type: ignore
            reactor = self.real_io_loop.run_sync(gen.coroutine(TornadoReactor))
            super(LayeredTwistedIOLoop, self).initialize(reactor=reactor, **kwargs)
            self.add_callback(self.make_current) 
Example #8
Source File: ioloop_test.py    From pySINDy with MIT License 5 votes vote down vote up
def test_remove_timeout_cleanup(self):
        # Add and remove enough callbacks to trigger cleanup.
        # Not a very thorough test, but it ensures that the cleanup code
        # gets executed and doesn't blow up.  This test is only really useful
        # on PollIOLoop subclasses, but it should run silently on any
        # implementation.
        for i in range(2000):
            timeout = self.io_loop.add_timeout(self.io_loop.time() + 3600,
                                               lambda: None)
            self.io_loop.remove_timeout(timeout)
        # HACK: wait two IOLoop iterations for the GC to happen.
        self.io_loop.add_callback(lambda: self.io_loop.add_callback(self.stop))
        self.wait() 
Example #9
Source File: ioloop_test.py    From pySINDy with MIT License 5 votes vote down vote up
def test_timeout_with_arguments(self):
        # This tests that all the timeout methods pass through *args correctly.
        results = []
        self.io_loop.add_timeout(self.io_loop.time(), results.append, 1)
        self.io_loop.add_timeout(datetime.timedelta(seconds=0),
                                 results.append, 2)
        self.io_loop.call_at(self.io_loop.time(), results.append, 3)
        self.io_loop.call_later(0, results.append, 4)
        self.io_loop.call_later(0, self.stop)
        self.wait()
        # The asyncio event loop does not guarantee the order of these
        # callbacks, but PollIOLoop does.
        self.assertEqual(sorted(results), [1, 2, 3, 4]) 
Example #10
Source File: ioloop_test.py    From pySINDy with MIT License 5 votes vote down vote up
def run_python(self, *statements):
        statements = [
            'from tornado.ioloop import IOLoop, PollIOLoop',
            'classname = lambda x: x.__class__.__name__',
        ] + list(statements)
        args = [sys.executable, '-c', '; '.join(statements)]
        return native_str(subprocess.check_output(args)).strip() 
Example #11
Source File: ioloop_test.py    From pySINDy with MIT License 5 votes vote down vote up
def test_default(self):
        if asyncio is not None:
            # When asyncio is available, it is used by default.
            cls = self.run_python('print(classname(IOLoop.current()))')
            self.assertEqual(cls, 'AsyncIOMainLoop')
            cls = self.run_python('print(classname(IOLoop()))')
            self.assertEqual(cls, 'AsyncIOLoop')
        else:
            # Otherwise, the default is a subclass of PollIOLoop
            is_poll = self.run_python(
                'print(isinstance(IOLoop.current(), PollIOLoop))')
            self.assertEqual(is_poll, 'True') 
Example #12
Source File: twisted_test.py    From pySINDy with MIT License 5 votes vote down vote up
def initialize(self, **kwargs):
            self.real_io_loop = PollIOLoop(make_current=False)  # type: ignore
            reactor = self.real_io_loop.run_sync(gen.coroutine(TornadoReactor))
            super(LayeredTwistedIOLoop, self).initialize(reactor=reactor, **kwargs)
            self.add_callback(self.make_current) 
Example #13
Source File: ioloop_test.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def test_remove_timeout_cleanup(self):
        # Add and remove enough callbacks to trigger cleanup.
        # Not a very thorough test, but it ensures that the cleanup code
        # gets executed and doesn't blow up.  This test is only really useful
        # on PollIOLoop subclasses, but it should run silently on any
        # implementation.
        for i in range(2000):
            timeout = self.io_loop.add_timeout(self.io_loop.time() + 3600,
                                               lambda: None)
            self.io_loop.remove_timeout(timeout)
        # HACK: wait two IOLoop iterations for the GC to happen.
        self.io_loop.add_callback(lambda: self.io_loop.add_callback(self.stop))
        self.wait()