<br><br><div class="gmail_quote">On Fri, Aug 28, 2009 at 7:49 PM, 陶艺夫 <span dir="ltr">&lt;<a href="mailto:artman328@gmail.com">artman328@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>I copied the code from: <a href="http://twistedmatrix.com/pipermail/twisted-python/2007-May/015377.html" target="_blank">http://twistedmatrix.com/pipermail/twisted-python/2007-May/015377.html</a> and it ran ok.<br>
And then I followed David&#39;s advice from here: <a href="http://twistedmatrix.com/pipermail/twisted-python/2007-May/015383.html" target="_blank">http://twistedmatrix.com/pipermail/twisted-python/2007-May/015383.html</a> to use threading.Event to control server&#39;s stop, it ran ok too. But David&#39;s boot_service.py just could install the service, error on start (error 1063). Any help?<br>

One more question, who can fill in David&#39;s &#39;py2exe&#39; setup file more codes to guide me  moving to next step? David, are you there? :)<br><br>Thanks.   <br>
</blockquote><div><br><br>看你的名字,我认为我写中文你应该能看懂。<br>我给你段可以通用的代码吧。<br><br>首先,是一个你要编译成ntservice的模块的文件。似设abcservice.py ,内容如下<br><br>#coding=utf-8<br>import win32serviceutil<br>import os<br>import sys<br>import win32api<br>sys.path = sys.path + [os.path.dirname(win32api.GetModuleFileName(0))]<br>
import server<br><br><br>class PowerService(win32serviceutil.ServiceFramework):<br>    _svc_name_ = &quot;Your Service Name&quot;<br>    _svc_display_name_ = &quot;Your Service Display Name&quot;<br>    _svc_description_ = unicode(&quot;&quot;&quot; 这里可以写多行的中文。<br>
也可以写 作者:你的名字。 <br>因为文件是utf-8的,在这里,要把中文转成gb2312,才能在windows里正常显示.<br>&quot;&quot;&quot;,&#39;utf-8&#39;).encode(&#39;gb2312&#39;)<br><br>    def SvcDoRun(self):<br>        server.start()<br><br>    def SvcStop(self):<br>        server.stop()<br>
<br>if __name__ == &#39;__main__&#39;:<br>    win32serviceutil.HandleCommandLine(PowerService)<br><br><br>用把这个程序打包成.exe以后,它就是一个可以通用的启动服务的程序了。<br>你的不同程序,只要在同一目录下,修改你的server.py文件,就可以了。<br><br><br>下面举例一个server.py<br><br>#coding=utf-8<br>
from twisted.internet import reactor<br><br>def start():<br>    reactor.run(installSignalHandlers=0)<br><br>def stop():<br>    reactor.callFromThread(reactor.stop)<br><br><br>下面是py2exe打包用的setup.py文件内容<br><br>rom distutils.core import setup<br>
import py2exe<br><br>import sys<br><br><br>setup(name=&#39;service name&#39;,<br>      version=&#39;1.0&#39;,<br>      author=&#39;your name&#39;,<br>      service=[&#39;abcservice&#39;])<br><br>print &quot;---Done---&quot;<br>
<br><br>然后用python setup.py py2exe命令打包。<br>打包好以后,就可以直接发布了。<br>如果缺什么模块,直接复到到abcservice.exe文件所有目录就行。<br>如果你的程序修改什么,只直接修改好代码,放在目录下就行。修改程序不用重新py2exe打包。<br><i><br><br></i></div></div><br>