Commit 52c58392 authored by Jeremy Hylton's avatar Jeremy Hylton

Reformat a smidgeon of code.

parent 12cc4e41
...@@ -128,57 +128,57 @@ else: ...@@ -128,57 +128,57 @@ else:
w.setsockopt(socket.IPPROTO_TCP, 1, 1) w.setsockopt(socket.IPPROTO_TCP, 1, 1)
# tricky: get a pair of connected sockets # tricky: get a pair of connected sockets
host='127.0.0.1' host = '127.0.0.1'
port=19999 port = 19999
while 1: while 1:
try: try:
self.address=(host, port) self.address = host, port
a.bind(self.address) a.bind(self.address)
break break
except: except:
if port <= 19950: if port <= 19950:
raise 'Bind Error', 'Cannot bind trigger!' raise 'Bind Error', 'Cannot bind trigger!'
port=port - 1 port -= 1
a.listen (1) a.listen(1)
w.setblocking (0) w.setblocking(0)
try: try:
w.connect (self.address) w.connect(self.address)
except: except:
pass pass
r, addr = a.accept() r, addr = a.accept()
a.close() a.close()
w.setblocking (1) w.setblocking(1)
self.trigger = w self.trigger = w
asyncore.dispatcher.__init__ (self, r) asyncore.dispatcher.__init__(self, r)
self.lock = thread.allocate_lock() self.lock = thread.allocate_lock()
self.thunks = [] self.thunks = []
self._trigger_connected = 0 self._trigger_connected = 0
def __repr__ (self): def __repr__(self):
return '<select-trigger (loopback) at %x>' % id(self) return '<select-trigger (loopback) at %x>' % id(self)
def readable (self): def readable(self):
return 1 return 1
def writable (self): def writable(self):
return 0 return 0
def handle_connect (self): def handle_connect(self):
pass pass
def pull_trigger (self, thunk=None): def pull_trigger(self, thunk=None):
if thunk: if thunk:
try: try:
self.lock.acquire() self.lock.acquire()
self.thunks.append (thunk) self.thunks.append(thunk)
finally: finally:
self.lock.release() self.lock.release()
self.trigger.send ('x') self.trigger.send('x')
def handle_read (self): def handle_read(self):
self.recv (8192) self.recv(8192)
try: try:
self.lock.acquire() self.lock.acquire()
for thunk in self.thunks: for thunk in self.thunks:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment