J.M.
J.M.

Reputation: 632

websocket await close vs await wait_closed

I'm using the websockets package on python and I'm opening a connection as a client,
but NOT in a block context like this:

async with websockets.connect(...) as websocket:
    ...

I'm opening the connection like this:

websocket = await websockets.connect(uri)

The thing is that I don't under stand what is the right way to close the connection.
The document explains here about await close() and await wait_closed(), but I don't understand the differences.

Does both are fine?
Should I use both?
If someone would share his experience it would be much appreciated.

Upvotes: 2

Views: 1982

Answers (1)

Artyom Vancyan
Artyom Vancyan

Reputation: 5390

The wait_closed is used to handle connection termination. And the close requests a connection termination and waits until the connection is closed. So if you want to close the connection you should use only await close().

Upvotes: 1

Related Questions