pymumble icon indicating copy to clipboard operation
pymumble copied to clipboard

Function to disconnect from current server without ending the program

Open enthrow opened this issue 5 years ago • 4 comments

Is there a function somewhere to manually disconnect from the server without exiting the program?

Also apologies for the issue on the mumbleradioplayer git, accidentally asked there first. Looking at the code for !kill on that project it seems that the command only exits completely when I just want to kill the thread

enthrow avatar May 06 '19 18:05 enthrow

no problem for the issue.

The simple answer is not. The main loop don't have reset/disconnect/stop feature.

You can force the state of self.connected and the loop will start the connection part again. It's should not hard to implement a real function for that, but I don't see any use case.

Az

azlux avatar May 06 '19 18:05 azlux

Thanks for the quick answer. I'll just hack something together for my very stupid use case.

enthrow avatar May 06 '19 18:05 enthrow

@enthrow Did you implement the disconnection functionality? If so, would you mind sharing the code with us?

ArniDagur avatar Jul 08 '19 11:07 ArniDagur

This works, but there's probably a better way to do it

diff --git a/pymumble_py3/mumble.py b/pymumble_py3/mumble.py
index 8b45e6f..6df3485 100644
--- a/pymumble_py3/mumble.py
+++ b/pymumble_py3/mumble.py
@@ -163,6 +163,12 @@ class Mumble(threading.Thread):
         self.connected = PYMUMBLE_CONN_STATE_AUTHENTICATING
         return self.connected

+    def close(self):
+        if self.connected == PYMUMBLE_CONN_STATE_CONNECTED:
+            self.reconnect = False
+            self.connected = PYMUMBLE_CONN_STATE_NOT_CONNECTED
+            self.control_socket.close()
+
     def loop(self):
         """
         Main loop

ArniDagur avatar Jul 08 '19 13:07 ArniDagur