0
我編寫了一個窗口服務在Python中連續寫入一些文本到一個文件,並安裝它並運行它,它工作正常。現在,如果我嘗試使用py2exe將我的python windows服務腳本轉換爲可執行文件(.exe)。 .exe作爲一項服務安裝正常,但是當我嘗試啓動它時,出現錯誤「服務器沒有及時響應啓動......」。這是有關py2exe破壞我的Python腳本中的信息。我該如何解決這個問題? (我想將它轉換爲.exe,因爲我想分發它)。使用py2exe很奇怪的Windows服務行爲
我的python腳本如下:
import win32service
import win32serviceutil
import win32event
class clear_queue(win32serviceutil.ServiceFramework):
_svc_name_ = "avant"
_svc_display_name_ = "avant"
_svc_description_ = "Elegant file writer"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self,args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
def SvcDoRun(self):
import servicemanager;
fil = open("C:/Users/u/Desktop/c99/user.txt",'r+');
rc = win32event.WaitForSingleObject(self.hWaitStop, 64)
while rc != win32event.WAIT_OBJECT_0:
fil.write("george\n");
rc = win32event.WaitForSingleObject(self.hWaitStop, 64)
def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
if __name__ == '__main__':
win32serviceutil.HandleCommandLine(clear_queue)