[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light
/ cpython Public
New 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

bpo-32391: Implement StreamWriter.wait_closed() #5281

Merged
merged 14 commits into from Jan 24, 2018

Conversation

Copy link
Contributor

asvetlov commented Jan 23, 2018

Copy link
Member

1st1 commented Jan 23, 2018

Please go ahead and add the tests.

Copy link
Contributor Author

asvetlov commented Jan 24, 2018

Done, please review

@@ -201,6 +201,16 @@ StreamWriter

Close the transport: see :meth:`BaseTransport.close`.

.. coroutinemethod:: wait_closed()

Wait for writer closing.
Copy link
Member

1st1 Jan 24, 2018

Choose a reason for hiding this comment

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

-> "Wait until the writer is closed."


Should be called after :meth:`close` to waiting for finishing
all writer activities (:meth:`BaseProtocol.connection_lost`
callback call actually).
Copy link
Member

1st1 Jan 24, 2018

Choose a reason for hiding this comment

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

-> "Should be called after :meth:close to wait until the underlying
connection (and the associated transport/protocol pair) is closed."

def __del__(self):
# Prevent reports about unhandled exceptions.
# Better than self._closed._log_traceback = False hack
if self._closed.done():
Copy link
Member

1st1 Jan 24, 2018

Choose a reason for hiding this comment

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

if self._closed.done() and not self._closed.cancelled()

Copy link
Member

1st1 Jan 24, 2018

Choose a reason for hiding this comment

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

Ideally need a test case for the cancelled check.

Copy link
Contributor Author

asvetlov Jan 24, 2018

Choose a reason for hiding this comment

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

Fixed.
Don you insist on test?
I see no way to make it steady without mocking everything.

Copy link
Member

1st1 Jan 24, 2018

Choose a reason for hiding this comment

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

If it's so hard to hit this then it's OK. I don't like super complex mocked tests anyways.


async def wait_closed(self):
if self._transport is not None:
await self._protocol._closed
Copy link
Member

1st1 Jan 24, 2018

Choose a reason for hiding this comment

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

When is the transport None? Can you add a comment?

Copy link
Contributor Author

asvetlov Jan 24, 2018

Choose a reason for hiding this comment

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

Actually I have no idea, just copied the line from drain.
Looking on source code there is no line for setting transport to None.
Let's drop the check from both methods.

@@ -303,6 +315,13 @@ def can_write_eof(self):
def close(self):
return self._transport.close()

def is_closing(self):
Copy link
Member

1st1 Jan 24, 2018

Choose a reason for hiding this comment

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

Is this a new API method? Please document it if it is.

Copy link
Contributor Author

asvetlov Jan 24, 2018

Choose a reason for hiding this comment

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

Forgot about the change - but exposing the method makes sense

Copy link
Member

1st1 Jan 24, 2018

Choose a reason for hiding this comment

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

I think it's a bit too low-level. Can you imagine a good use case for async/await code that uses writer and reader?

Copy link
Contributor Author

asvetlov Jan 24, 2018

Choose a reason for hiding this comment

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

StreamWriter exposes all Transport methods except flow control related.
is_closing() is not about flow control, I see no reason to not implement it.

Copy link
Member

1st1 Jan 24, 2018

Choose a reason for hiding this comment

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

OK, go ahead.

@@ -0,0 +1 @@
Implement :meth:`asyncio.StreamWriter.wait_closed` method
Copy link
Member

1st1 Jan 24, 2018

Choose a reason for hiding this comment

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

And is_closing() ?

Copy link
Contributor Author

asvetlov commented Jan 24, 2018

Please review again.

@@ -0,0 +1 @@
Implement :meth:`asyncio.StreamWriter.wait_closed` and :meth:`asyncio.StreamWriter.is_closing` methods
Copy link
Member

1st1 Jan 24, 2018

Choose a reason for hiding this comment

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

One last note: I don't think you want to use ReST formatting in NEWS entries. This would read better:

Implement wait_closed() and is_closing() methods for StreamWriter.

Copy link
Contributor Author

asvetlov Jan 24, 2018

Choose a reason for hiding this comment

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

There is no standard for blurb text, the format of messages is mixed.
Some people use ReST, others prefer plain text.
If you briefly look on these files you'll see both cases.

I have no personal preference.

Copy link
Member

1st1 Jan 24, 2018

Choose a reason for hiding this comment

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

I don't really care.

1st1 approved these changes Jan 24, 2018
data = self.loop.run_until_complete(f)
self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
wr.close()
self.loop.run_until_complete(wr.wait_closed())
Copy link
Member

1st1 Jan 24, 2018

Choose a reason for hiding this comment

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

Add assertTrue(wr.is_closing())

f = rd.read()
data = self.loop.run_until_complete(f)
self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
wr.close()
Copy link
Member

1st1 Jan 24, 2018

Choose a reason for hiding this comment

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

Add assertFalse(wr.is_closing()) before wr.close()

Copy link
Member

1st1 commented Jan 24, 2018

LGTM.

asvetlov merged commit fe133aa into python:master Jan 24, 2018
asvetlov deleted the asyncio-streams branch Jan 24, 2018
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.

None yet

4 participants