def __enforce_no_existing_ppp_session(self): pid_list = self.__check_for_existing_ppp_sessions() if len(pid_list) > 0: raise PPPError('Existing PPP session(s) are established by pid(s) %s. Please close/kill these processes first' % pid_list)
def __enforce_no_existing_ppp_session(self): process = self.__check_for_existing_ppp_sessions() if process is None: return pid = process.split(' ')[1] raise PPPError( 'An existing PPP session established by pid %s is currently using the %s device interface. Please close/kill that process first' % (pid, self.device_name))
def waitForPPPSuccess(self, timeout): starttime = time.time() while (time.time() - starttime) < timeout: self.readFromPPP() if self.laddr is not None and self.raddr is not None: return True if 'Modem hangup' in self.output: raise PPPError('Modem hangup - possibly due to an unregistered SIM') elif self.proc.poll(): raise PPPConnectionError(self.proc.returncode, self.output) return False
def __check_for_existing_ppp_sessions(self): existing_ppp_pids = [] self.logger.info('Checking for existing PPP sessions') for proc in psutil.process_iter(): try: pinfo = proc.as_dict(attrs=['pid', 'name']) except: raise PPPError('Failed to check for existing PPP sessions') if 'pppd' in pinfo['name']: self.logger.info('Found existing PPP session on pid: %s', pinfo['pid']) existing_ppp_pids.append(pinfo['pid']) return existing_ppp_pids
def connectThreadedFunc(self, result): while True: try: self.output += self.proc.stdout.read() except IOError as e: if e.errno != 11: raise time.sleep(1) if self.laddr != None and self.raddr != None: result[0] = True return if 'Modem hangup' in self.output: raise PPPError('Modem hangup - possibly due to an unregistered SIM') elif self.proc.poll(): raise PPPConnectionError(self.proc.returncode, self.output)