Reputation: 745
I am using twisted reactor to non-block reading sockets input. however, I want to run another loop after reactor starting running
.....
reactor.listenTCP(12345, MyFactory())
reactor.run()
# ... blah blah socket input related code
while 1:
...
...
if something:
reactor.stop()
Problem is after reactor.run()
the while
loop will not working.
May I know rather than using threading in main te = Thread(target=reactor.run, args=(False,)).start()
, any other way can make reactor.run()
working on non-blocking?
Thank you.
Upvotes: 4
Views: 1758
Reputation: 494
reactor.run()
is a blocking call. You will need to do something like, run your loop in a separate thread. The way you have it, your loop will run, but only if you manage to stop the reactor via some external event or signal. At that time, the call to reactor.run()
will return, and the remainder of your code will execute.
I am actually looking for a way to call reactor.run()
in a non-blocking way myself. If anyone has a way to do that, I would love to hear about it.
Upvotes: 5