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:
JavaScript
x
3
1
async with websockets.connect( ) as websocket:
2
3
I’m opening the connection like this:
JavaScript
1
2
1
websocket = await websockets.connect(uri)
2
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.
Advertisement
Answer
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()
.