Skip to content

Commit

Permalink
Merge pull request #254 from ska-sa/user/tockards/test-asyncioloop-on…
Browse files Browse the repository at this point in the history
…-ioloop-manager

Add asyncio compatible ioloop to ioloop manager
  • Loading branch information
Toufeeq Ockards committed Feb 2, 2021
2 parents f7ece1b + 61a07e3 commit 9d681c7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
29 January 2021 (0.9.0)
* Add asyncio compatible ioloop to ioloop manager (PR [#254](https://github.com/ska-sa/katcp-python/pull/254))

29 October 2020 (0.8.0)
* Add bulk sensor sampling feature (PR [#197](https://github.com/ska-sa/katcp-python/pull/197))

Expand Down
4 changes: 4 additions & 0 deletions doc/releasenotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
Release Notes
*************

0.9.0
=====
* Add asyncio compatible ioloop to ioloop manager.

0.8.0
=====
* Added bulk sensor sampling feature.
Expand Down
8 changes: 7 additions & 1 deletion katcp/ioloop_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
from tornado import gen
from tornado.concurrent import Future as tornado_Future

if sys.version_info[0] == 3:
from tornado.platform.asyncio import AsyncIOLoop

from katcp.object_proxies import ObjectWrapper


Expand Down Expand Up @@ -52,7 +55,10 @@ def managed(self):
def get_ioloop(self):
if not self._ioloop:
if self._ioloop_managed:
self.set_ioloop(tornado.ioloop.IOLoop())
if sys.version_info[0] == 3:
self.set_ioloop(AsyncIOLoop())
else:
self.set_ioloop(tornado.ioloop.IOLoop())
else:
self.set_ioloop(tornado.ioloop.IOLoop.current())
return self._ioloop
Expand Down
14 changes: 14 additions & 0 deletions katcp/test/test_ioloop_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from future import standard_library
standard_library.install_aliases() # noqa: E402

import sys
import unittest

from builtins import object
Expand Down Expand Up @@ -64,3 +65,16 @@ def only_in_ioloop(self):
self.assertEqual(wrapped.a_callable(5, kwarg='bcd'), (10, 'bcd'*3))
self.assertEqual(wrapped.only_in_ioloop, 'only_in')
self.assertEqual(wrapped.not_in_ioloop, 'not_in')


class test_IOLoopManager(unittest.TestCase):
def setUp(self):
self.ioloop_manager = ioloop_manager.IOLoopManager(managed_default=True)
self.ioloop = self.ioloop_manager.get_ioloop()
start_thread_with_cleanup(self, self.ioloop_manager, start_timeout=1)

def test_managed_io_loop_is_asyncio_in_python3(self):
if sys.version_info[0] == 3:
self.assertTrue(hasattr(self.ioloop, "asyncio_loop"))
else:
self.assertFalse(hasattr(self.ioloop, "asyncio_loop"))

0 comments on commit 9d681c7

Please sign in to comment.