<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.apple-tab-span
        {mso-style-name:apple-tab-span;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple style='word-wrap: break-word;
-webkit-nbsp-mode: space;-webkit-line-break: after-white-space'>

<div class=Section1>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>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&#8217;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.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>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 &nbsp;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&#8217;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&#8217;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&#8230;. I&#8217;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&#8217;t
an uncommon complaint, so solving it seems useful.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>-Jared<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<div>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>

<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
twisted-python-bounces@twistedmatrix.com
[mailto:twisted-python-bounces@twistedmatrix.com] <b>On Behalf Of </b>Paul
Thomas<br>
<b>Sent:</b> Friday, July 03, 2009 2:31 AM<br>
<b>To:</b> Twisted general discussion<br>
<b>Subject:</b> Re: [Twisted-Python] untwisting twistd<o:p></o:p></span></p>

</div>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<div>

<div>

<p class=MsoNormal>On 2 Jul 2009, at 23:50, Mikhail wrote:<o:p></o:p></p>

</div>

<p class=MsoNormal><br>
<br>
<o:p></o:p></p>

<div>

<p class=MsoNormal><br>
In my example I should have written <br>
<br>
&nbsp;&nbsp;&nbsp;run(application)<br>
<br>
instead of <br>
<br>
&nbsp;&nbsp;&nbsp;run(...)<br>
<br>
Then the difference would be more apparent. Namely, in my 'wrapper'<br>
it is explicit what application will be run and where all the services<br>
came from, your 'wrapper' is just a customized version of twistd and <br>
what will be run depends on the command line and what will be found <br>
in the file system. In some cases I'd like to _explicitly_ code into <br>
main script what functionality my application provides and I do not<br>
want twistd search file system for plugins at all.<o:p></o:p></p>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<div>

<p class=MsoNormal>I'm&nbsp;not&nbsp;using&nbsp;plugins,&nbsp;but&nbsp;I&nbsp;had&nbsp;the&nbsp;same&nbsp;requirement&nbsp;as&nbsp;you&nbsp;to&nbsp;explicitly&nbsp;create&nbsp;the&nbsp;app&nbsp;and&nbsp;then&nbsp;run&nbsp;it&nbsp;-&nbsp;because&nbsp;I&nbsp;need&nbsp;the&nbsp;freeze&nbsp;scripts&nbsp;to&nbsp;make&nbsp;a&nbsp;single&nbsp;application.<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<div>

<p class=MsoNormal>My&nbsp;solution&nbsp;looked&nbsp;something&nbsp;like:<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<div>

<p class=MsoNormal># myapp.py<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<div>

<p class=MsoNormal>from twisted.scripts._twistd_unix import
UnixApplicationRunner<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal># Of course, that's just because the app is unix only<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<div>

<p class=MsoNormal>class MyRunner(UnixApplicationRunner):<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><span class=apple-tab-span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>def
createOrGetApplication(self):<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><span class=apple-tab-span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>#
The stuff that's usually in a tac file<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><span class=apple-tab-span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>application
= # ...<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><span class=apple-tab-span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>return
application<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<div>

<p class=MsoNormal>def main():<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><span class=apple-tab-span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>setup_logging()<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><span class=apple-tab-span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>config
= { # stuff pinched by dumping 'config' during a twistd run<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><span class=apple-tab-span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><span class=apple-tab-span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>#
Also do the ServerOptions thing here if necessary<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><span class=apple-tab-span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>MyRunner(config).run()<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<div>

<p class=MsoNormal>if __name__ == '__main__'<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><span class=apple-tab-span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>main()<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

</div>

</body>

</html>