2010-12-21 77 views
3

我有一個最小的蟒蛇Win32服務service.py是沒有什麼特別之處:Python的Win32服務

import win32serviceutil 
import win32service 
import win32event 

class SmallestPythonService(win32serviceutil.ServiceFramework): 
    _svc_name_ = "SmallestPythonService" 
    _svc_display_name_ = "display service" 
    # _svc_description_='ddd' 

    def __init__(self, args):  
     win32serviceutil.ServiceFramework.__init__(self, args) 
     self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) 

    def SvcStop(self): 
     self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) 
     win32event.SetEvent(self.hWaitStop) 

    def SvcDoRun(self):  
     win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE) 

if __name__=='__main__': 
    win32serviceutil.HandleCommandLine(SmallestPythonService) 

當我運行:

service.py install 
service.py start 

它工作正常,但是當我編譯service.py文件,py2exeservice.exe並運行以下命令:

service.exe install 
service.exe start [or trying to restart the service from the Services.msc] 

我收到此消息:

Could not start the service name service on Local Computer. 
Error 1053: The service did not respond to the start or control request in a timely fashion 

我該如何解決此問題?

而且,這裏的distutil代碼:

from distutils.core import setup 
import py2exe 

py2exe_options = {"includes": ['decimal'],'bundle_files': 1} 

setup(console=[{"script":'Service.py'}], 
    options={"py2exe": py2exe_options}, 
    zipfile = None, 
    }, 
) 

回答

0

快速谷歌想出了這一點:http://islascruz.org/html/index.php?gadget=StaticPage&action=Page&id=6

它有意大利的評論,但我可以幫你翻譯一些東西,如果你不知道意大利。與setup(service=[{"script":'Service.py'}]setup(console=[{"script":'Service.py'}]

要真正地調試你的問題,我想我們需要看到您的setup.py的distutils腳本...

+0

您好我添加了setup.py代碼。 – AKM 2010-12-21 13:55:50

6

更換你。而不是控制檯使用服務。

0

您可能會錯過找到該服務所需的所有DLL的正確PATH。通常該服務被安裝爲「LocalSystem」服務,因此您需要將PATH添加到系統(而不是用戶)。

嘗試在系統路徑中添加c:\ python27(或任何您的python dll的路徑),重新啓動計算機並檢查它現在是否可以正常啓動。

1

試試這個設置:

py2exe_options = {"includes": ['decimal'],'bundle_files': 1} 
setup(
    service=[{'modules':'Service.py','cmdline_style':'pywin32','description':'your service description'}], 
    options={'py2exe':py2exe_options}, 
    zipfile=None)