Skip to content

Commit 6c0983c

Browse files
committed
handle callbacks
1 parent c461b26 commit 6c0983c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

rsc.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@ def broadcast(small_dir, data):
122122
def gotProtocol(p):
123123
p.sendLine(data)
124124

125-
def timeout(exp):
126-
print "Timeout?", exp
127-
raise exp
128-
129125
for (kid, ip, port) in small_dir:
130126
_stats[ip] += 1
131127
point = TCP4ClientEndpoint(reactor, ip, int(port), timeout=10)
@@ -307,13 +303,20 @@ def main():
307303
cores += [ c ]
308304

309305
def play_another_song(var):
310-
#if var:
311-
# print "ERROR", var
306+
if var is not None and (not isinstance(var, float) or not isinstance(var, float)):
307+
print "ERROR", var
312308

313309
if cores != []:
314310
c = cores.pop()
315311
d = play(c, directory)
316-
d.addBoth(play_another_song)
312+
d.addCallback(play_another_song)
313+
314+
def replay():
315+
cores += [ c ]
316+
317+
d.addErrback(replay)
318+
d.addErrback(play_another_song)
319+
317320
else:
318321
threads.pop()
319322
if threads == []:
@@ -325,6 +328,7 @@ def play_another_song(var):
325328
t0 = default_timer()
326329
reactor.run()
327330
t1 = default_timer()
331+
328332
print "Overall time: %s" % (t1 - t0)
329333
for (ip, v) in sorted(_stats.iteritems()):
330334
print "Stats: %s %s" % (ip, v)

0 commit comments

Comments
 (0)