diff options
author | Srinivas Reddy Thatiparthy (శ్రీనివాస్ రెడ్డి తాటిపర్తి) <srinivasreddy@users.noreply.github.com> | 2017-12-30 15:09:32 (GMT) |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2017-12-30 15:09:32 (GMT) |
commit | 1634fc289a13b0e1fdad4694d5cae7dab55f7186 (patch) | |
tree | 4973b8e55ffe557c712763c0be5a70946b9fd211 | |
parent | fc35932afdad91f87b49a4854d4333267494c6c1 (diff) | |
download | cpython-1634fc289a13b0e1fdad4694d5cae7dab55f7186.zip cpython-1634fc289a13b0e1fdad4694d5cae7dab55f7186.tar.gz cpython-1634fc289a13b0e1fdad4694d5cae7dab55f7186.tar.bz2 |
bpo-32418: Add get_loop() method on Server, AbstractServer classes (#4997)
* Add abstract get_loop() method to Server, AbstractServer classes.
* Add test cases for get_loop() method in Server, AbstractServer classes
* Add documentation for get_loop() method
-rw-r--r-- | Doc/library/asyncio-eventloop.rst | 6 | ||||
-rw-r--r-- | Lib/asyncio/base_events.py | 3 | ||||
-rw-r--r-- | Lib/asyncio/events.py | 4 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_events.py | 13 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Documentation/2017-12-24-17-29-37.bpo-32418.eZe-ID.rst | 1 |
5 files changed, 27 insertions, 0 deletions
diff --git a/Doc/library/asyncio-eventloop.rst b/Doc/library/asyncio-eventloop.rst index 33b86d6..4fbbcd8 100644 --- a/Doc/library/asyncio-eventloop.rst +++ b/Doc/library/asyncio-eventloop.rst @@ -913,6 +913,12 @@ Server The server is closed asynchronously, use the :meth:`wait_closed` coroutine to wait until the server is closed. + .. method:: get_loop() + + Gives the event loop associated with the server object. + + .. versionadded:: 3.7 + .. coroutinemethod:: wait_closed() Wait until the :meth:`close` method completes. diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index 00831b3..ab00231 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -185,6 +185,9 @@ class Server(events.AbstractServer): if self._active_count == 0: self._wakeup() + def get_loop(self): + return self._loop + def _wakeup(self): waiters = self._waiters self._waiters = None diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py index 9496d5c..731a0c5 100644 --- a/Lib/asyncio/events.py +++ b/Lib/asyncio/events.py @@ -155,6 +155,10 @@ class AbstractServer: """Coroutine to wait until service is closed.""" return NotImplemented + def get_loop(self): + """ Get the event loop the Server object is attached to.""" + return NotImplemented + class AbstractEventLoop: """Abstract event loop.""" diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py index da2e036..e832056 100644 --- a/Lib/test/test_asyncio/test_events.py +++ b/Lib/test/test_asyncio/test_events.py @@ -2826,6 +2826,19 @@ else: get_running_loop_impl = events._c_get_running_loop get_event_loop_impl = events._c_get_event_loop +class TestServer(unittest.TestCase): + + def test_get_loop(self): + loop = asyncio.new_event_loop() + proto = MyProto(loop) + server = loop.run_until_complete(loop.create_server(lambda: proto, '0.0.0.0', 0)) + self.assertEqual(server.get_loop(), loop) + loop.close() + +class TestAbstractServer(unittest.TestCase): + + def test_get_loop(self): + self.assertEqual(events.AbstractServer().get_loop(), NotImplemented) if __name__ == '__main__': unittest.main() diff --git a/Misc/NEWS.d/next/Documentation/2017-12-24-17-29-37.bpo-32418.eZe-ID.rst b/Misc/NEWS.d/next/Documentation/2017-12-24-17-29-37.bpo-32418.eZe-ID.rst new file mode 100644 index 0000000..9441b74 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2017-12-24-17-29-37.bpo-32418.eZe-ID.rst @@ -0,0 +1 @@ +Add get_loop() method to Server and AbstractServer classes. |