Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

stream writer.close() is not awaitable #466

Description

@asvetlov

The problem is: writer.close() is a regular method which calls transport.close().

But transport.close() actually closes the connection only on next loop iteration by self._loop.call_soon(self._call_connection_lost, None) call`.

Now a safe way for stream closing is

writer.close()
await sleep(0)

but it looks ugly.

I see two possible solutions:

  1. Introducing writer.wait_closed() coroutine.
  2. Changing writer.close() signature to return a future object. The future will be resumed on protocol's connection_lost() callback.

Honestly I vote on point 2: it looks more native and fully backward compatible with existing code.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions