8000 bpo-32418: Add get_loop() method on Server, AbstractServer classes by srinivasreddy · Pull Request #4997 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-32418: Add get_loop() method on Server, AbstractServer classes #4997

New 8000 issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 30, 2017
Merged

bpo-32418: Add get_loop() method on Server, AbstractServer classes #4997

merged 4 commits into from
Dec 30, 2017

Conversation

srinivasreddy
Copy link
Contributor
@srinivasreddy srinivasreddy commented Dec 23, 2017

@1st1
Copy link
Member
1st1 commented Dec 23, 2017

Please add tests/NEWS entry/docs.

@@ -155,6 +155,10 @@ def close(self):
"""Coroutine to wait until service is closed."""
return NotImplemented

def get_loop(self):
""" Get the event loop"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

""" Get the event loop""" -> """Get the event loop the Server object is attached to."""

@srinivasreddy srinivasreddy changed the title bpo-32418: Add abstract get_loop() method bpo-32418: Add get_loop() method on Server, AbstractServer classes Dec 23, 2017
@@ -0,0 +1 @@
Add get_loop method to Server and AbstractServer classes attached to - bpo:32418
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop bpo number: it will be added automatically by blurb.

@@ -179,6 +179,9 @@ def close(self):
if self._active_count == 0:
self._wakeup()

def get_loop(self):
return self._loop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test for the method.

Copy link
Contributor Author
@srinivasreddy srinivasreddy Dec 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot find tests for Server class. Could you help me please? Or it looks like i need to write test cases for Server class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loop.create_server returns Server objects.

@@ -155,6 +155,10 @@ def close(self):
"""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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test for make sure that AbstractServer().get_loop() returns NotImplemented.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asvetlov It should raise NotImplementedError, please fix. NotImplemened singleton is for comparisons in Python.

Copy link
Contributor
@asvetlov asvetlov Dec 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh, my bad.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
proto = MyProto(loop)
server = loop.create_server(lambda: proto, '0.0.0.0', 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is a coroutine, use server = loop.run_until_complete(loop.create_server(lambda: proto, '0.0.0.0', 0))


def test_get_loop(self):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call is not needed but loop should be closed after the test.

@srinivasreddy
Copy link
Contributor Author
srinivasreddy commented Dec 26, 2017

@asvetlov Done. Thanks!! Do i need to update the documentation? Looks like it.

@srinivasreddy
Copy link
Contributor Author

@asvetlov I have updated the docs, pls let me know what do you think?

@asvetlov
Copy link
Contributor

Should be documented not AbstractEventLoop.create_server but Server here: https://docs.python.org/3.7/library/asyncio-eventloop.html#server

@srinivasreddy
Copy link
Contributor Author

@asvetlov Done.

@asvetlov
Copy link
Contributor

Thanks!

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will leak an open server object. Add server.close(); loop.run_until_complete(server.wait_closed())

@1st1
Copy link
Member
1st1 commented Dec 30, 2017

@asvetlov There are a couple of issues with this PR, please fix if possible.

@srinivasreddy srinivasreddy deleted the 32418 branch December 30, 2017 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0