def connect(self, timeout = DEFAULT_CONNECT_TIMEOUT):
self.proc = Popen(self._commands, stdout=PIPE, stderr=STDOUT, universal_newlines=True)
# set stdout to non-blocking
fd = self.proc.stdout.fileno()
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
result = [False]
self._connectThread = threading.Thread(target = self.connectThreadedFunc,
args = [result])
self._connectThread.daemon = True
self._connectThread.start()
self._connectThread.join(timeout)
# If thread is still alive, tear down pppd connection and kill the thread.
if self._connectThread.is_alive():
self._connectThread.join(1)
self.proc.send_signal(signal.SIGTERM)
time.sleep(1)
return result[0]
# EFFECTS: Establish a cellular connection. Returns true if successful,
# false otherwise.
评论列表
文章目录