I have the following code. I am trying to get reactor to run on the ports starting at 1025 + NUM_TABLES. The issue is that when I call reactor.run() in the loop, the loop freezes. When it is commented, the loop counts from 0 to 9, but when it is uncommented, it only prints 0.
NUM_TABLES = 10
factories = [ ]
for i in range(0, NUM_TABLES):
print i
factory = Factory()
factory.protocol = Socket
factory.clients = []
factories.append(factory)
reactor.listenTCP(1025+i, factory)
#print "Blackjack server started"
reactor.run()
WHat does it take to be able to run a new factory on a different port? Why does reactor stop at 0? It has worked before, why not now? Thanks.
Don’t call
reactor.run()until all of your listeners have been created and registered. It’s meant to be the last call you make directly from your main script; everything after that is callbacks.To clarify, just un-indent the last line one level.