self.sock = None
self.connected = False
- def connect(self):
+ def connect(self, retry=10000):
if self.sock != None:
return
log("connect to", self.path)
- s = open(self.path,"r+")
+ s = None
+ while s == None and retry > 0:
+ retry -= 1
+ try:
+ s = open(self.path,"r+")
+ except IOError:
+ time.sleep(0.4)
+ s = None
+ if not s:
+ return False
#s.setblocking(0)
fd = s.fileno()
attr = termios.tcgetattr(fd)
attr[6][termios.VMIN] = 0
attr[6][termios.VTIME] = 0
termios.tcsetattr(fd, termios.TCSANOW, attr)
-
+
self.watcher = gobject.io_add_watch(s, gobject.IO_IN, self.readdata)
self.sock = s
self.connected = True
+ return True
def readdata(self, io, arg):
try:
self.timer = None
self.timedout()
return False
-
+
def set_timeout(self, delay):
if self.pending:
raise ValueError
if self.pending:
gobject.source_remove(self.timer)
self.pending = False
-
+
def abort_timeout(self):
if self.pending:
self.cancel_timeout()