Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def disconnect(self):
if self.vpn_process is not None:
try:
self._terminate()
except ValueError:
self._kill()
time.sleep(0.5)
while self._is_running:
if self.use_pexpect:
try:
self.vpn_process.close(True)
except ptyprocess.ptyprocess.PtyProcessError:
pass
else:
self.vpn_process.wait()
time.sleep(0.1)
self.connected = False
try:
self.instances.remove(self)
except ValueError:
pass
self.vpn_process = self.ip = self.conf_file = None
self.log.info('Disconnected')
else:
self.log.warning('Not connected')