What is the best way to control a vortex reactor so that it does not block?

Instead of starting the .run () reactor, I would like to name something else (I don't know, for example, reactor.runOnce () or something), sometimes saving my own main loop. Is there any best practice for this with perverted?

+6
python twisted nonblocking
source share
1 answer

Yes. Best practice is that this is a bad idea and that you never need to do this. It does not work with all reactors, and of course you cannot have two different libraries that want to do this.

Why do you need your own main loop? Most likely, it is something like “I want to work with PyGame” or “I am writing a GUI program and I want to use GTK mainloop” or “I use Twisted from within Blender and have my own event handling”. If so, you should ask a specific question, because each of them has its own answer.

If you absolutely must do this (and again: you won’t), the way to do this is to periodically call reactor.iterate() . This will be slow, interrupt signal processing and wkyky semantics with respect to reactor.stop() . This will lead to many errors in your program that would otherwise not be there, and when you need help diagnosing them if you ask someone from the Twisted dev team, the first thing they will tell you is “stop it do, "This needs to be done."

+11
source share

All Articles