Instead of running reactor.run(), I'd like to call something else (I dunno, like reactor.runOnce() or something) occasionally while maintaining my own main loop. Is there a best-practice for this with twisted?
Yes. The best practice is that this is a bad idea, and that you never really need to do it. It doesn't work with all reactors, and you certainly can't have two different libraries which want to do this.
Why do you need to maintain your own main loop? Chances are, it's something like "I want to work with PyGame" or "I am writing a GUI program and I want to use GTK's mainloop" or "I'm using Twisted from within Blender and it has its own event-handling". If this is the case, you should ask that specific question, because each one of those has its own answer.
If you absolutely need to do this (and, again: you don't) the way to do it is to call reactor.iterate()
periodically. This will be slow, break signal handling, and have wonky semantics with respect to reactor.stop()
. It will introduce lots of bugs into your program that wouldn't otherwise be there, and when you need help diagnosing them, if you ask someone on the Twisted dev team, the first thing they will tell you is "stop doing that, you don't need to do it".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With