My boss and I finally have a VERY basic web front end working in Django that kicks off when a user goes to a certain URL. The script queries a network device and returns the output to the screen. The script is using Twisted in the background and it works great. The problem is that if a user goes to that URL a second time, we get an error that says reactor is not restartable. In order for someone to hit that URL more than once, we have to restart Apache after every run. Clearly not a scalable solution! We ultimately want to have a front end that can select from multiple scripts, provide input, etc., but I'm not sure how we'll pull it off with this setup.
Do any of you have any ideas how we could have interactive front ends to multiple scripts that use trigger in the background? If we keep running into these sorts of issues, I may have to jettison Trigger and just use pexpect, which works but is far, far more verbose. My boss thought perhaps within Django we could spawn a child process to run the Trigger/Twisted stuff, so maybe that would destroy the old process and allow us to run the script again without running into the "reactor not restartable" error all the time.
What do you think?
Thanks!
--
You received this message because you are subscribed to the Google Groups "Trigger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trigger-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Hmm, if I understand the Trigger / Commando documentation correctly, it shouldn't be a problem. (Note that Commando's management of the event loop is essentially the same thing as what Crochet does: if you use that, you don't need something like Crochet.)
To solve this, you probably have two options:
1. Make your main Commando
instance module-global, instead of dynamically constructing and destroying it somewhere (which is what I'm guessing is currently happening, due to the symptoms). If you make the Commando
instance global, it will persist between Django's individual request/response handling cycles, and won't stop the reactor prematurely.
2. Use CommandoApplication
instead of Commando
, and let Crochet manage the reactor instead. CommandoApplication
is a subclass of Commando
that doesn't manage the reactor for you, so you don't have to worry about its lifecycle, or make it global, and can run the reactor however you wish (twistd, or Crochet, or manually).
All of this probably sounds a lot more complicated than it actually is. Try the first option, first: if caching or making the Commando
instance module global solves it, you should be good to go, and can trust Commando to take care of the rest.