Mikhail is correct in what needs to be done here. Twistd should provide helpers to writing an application without being the application. Not every wants to make it look like they're using twisted, even if they are. Having a twistd process appear in my process list is unacceptable, and my applications takes a well know and singular config. Twistd should be nothing more than a general helper.
Ultimately what Mikhail shows is very similar to what I have done by import directly the ApplicationRunner I want to use (my app is also Unix-only), and then subclassing ServerOptions. I also modified createorGetApplication to return an application object instead of loading it from some damned .tac file that is passed in on the CLI, which was exactly the thing that was trying to be avoided. My application is defined already in code, so I should be able to create my application object, and pass it right into a runner with proper application options and have it fire up avoiding the generalities of twistd that don't apply to me. Again, twistd is great at supporting one use case. It needs to support others, and it needs to be refactored just a bit more to do that. It wouldn't be as difficult to do this as you probably imagine, and proper documentation on more ways it could be used would save developers a ton of time. Now, if I only had the time to get this done.... I'll see if I can refactor and provide some sample code to at serves the use case we are discussing here. As I was told early on in this inquiry, this problem isn't an uncommon complaint, so solving it seems useful. -Jared From: twisted-python-boun...@twistedmatrix.com [mailto:twisted-python-boun...@twistedmatrix.com] On Behalf Of Paul Thomas Sent: Friday, July 03, 2009 2:31 AM To: Twisted general discussion Subject: Re: [Twisted-Python] untwisting twistd On 2 Jul 2009, at 23:50, Mikhail wrote: In my example I should have written run(application) instead of run(...) Then the difference would be more apparent. Namely, in my 'wrapper' it is explicit what application will be run and where all the services came from, your 'wrapper' is just a customized version of twistd and what will be run depends on the command line and what will be found in the file system. In some cases I'd like to _explicitly_ code into main script what functionality my application provides and I do not want twistd search file system for plugins at all. I'm not using plugins, but I had the same requirement as you to explicitly create the app and then run it - because I need the freeze scripts to make a single application. My solution looked something like: # myapp.py from twisted.scripts._twistd_unix import UnixApplicationRunner # Of course, that's just because the app is unix only class MyRunner(UnixApplicationRunner): def createOrGetApplication(self): # The stuff that's usually in a tac file application = # ... return application def main(): setup_logging() config = { # stuff pinched by dumping 'config' during a twistd run } # Also do the ServerOptions thing here if necessary MyRunner(config).run() if __name__ == '__main__' main()
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python