diff options
| author | Rapptz <[email protected]> | 2017-05-02 20:25:54 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-05-02 20:25:54 -0400 |
| commit | 663315f7ac6b3adde3ccfac8d348ebbc76fcf6d4 (patch) | |
| tree | 28588367c29f1caa11a3b85003dfba1474b6be33 | |
| parent | Fix NameError in HTTPClient.kick (diff) | |
| download | discord.py-663315f7ac6b3adde3ccfac8d348ebbc76fcf6d4.tar.xz discord.py-663315f7ac6b3adde3ccfac8d348ebbc76fcf6d4.zip | |
Explicitly close UDP sockets when re-creating them.
This does not actually make a big difference since the GC should
technically close them when needed but might as well be more explicit.
| -rw-r--r-- | discord/voice_client.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/discord/voice_client.py b/discord/voice_client.py index e1e6fce7..627c6159 100644 --- a/discord/voice_client.py +++ b/discord/voice_client.py @@ -94,6 +94,7 @@ class VoiceClient: self.main_ws = None self.timeout = timeout self.ws = None + self.socket = None self.loop = state.loop self._state = state # this will be used in the AudioPlayer thread @@ -174,6 +175,13 @@ class VoiceClient: self.endpoint = endpoint.replace(':80', '') self.endpoint_ip = socket.gethostbyname(self.endpoint) + + if self.socket: + try: + self.socket.close() + except: + pass + self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.socket.setblocking(False) @@ -254,7 +262,8 @@ class VoiceClient: yield from self.ws.close() yield from self.terminate_handshake(remove=True) finally: - self.socket.close() + if self.socket: + self.socket.close() @asyncio.coroutine def move_to(self, channel): |