Python win32 服务
我有一个最小的 python win32 服务 service.py
,它没有什么特别的:
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
它工作正常,但是当我使用 py2exe 编译
到 service.py
文件时service.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,
},
)
I have a minimal python win32 service service.py
that does nothing special:
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)
When I run:
service.py install
service.py start
it works fine but when I compile the service.py
file with py2exe
to service.exe
and run the following:
service.exe install
service.exe start [or trying to restart the service from the Services.msc]
I get this message:
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
How can I resolve this problem?
Also here the distutil
code:
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,
},
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将您的:
setup(console=[{"script":'Service.py'}]
替换为setup(service=[{"script":'Service.py'}]
代码>. 而不是控制台使用服务。Replace your:
setup(console=[{"script":'Service.py'}]
withsetup(service=[{"script":'Service.py'}]
. Instead of console use service.尝试这个设置:
try this setup:
快速谷歌想出了这个: http://islascruz .org/html/index.php?gadget=StaticPage&action=Page&id=6
它有意大利语注释,但如果您不懂意大利语,我可以帮助您翻译一些内容。
要真正调试您的问题,我想我们需要查看您的
setup.py
distutils 脚本...A quick google came up with this: http://islascruz.org/html/index.php?gadget=StaticPage&action=Page&id=6
It has Italian comments, but I can help you translate some stuff if you don't know Italian.
To truly debug your problem, I guess we will need to see your
setup.py
distutils script...您可能缺少用于查找服务所需的所有 DLL 的正确路径。通常该服务作为“本地系统”服务安装,因此您需要将 PATH 添加到系统(而不是用户)。
尝试将 c:\python27 (或 python dll 的任何路径)添加到系统路径中,重新启动计算机并检查它现在是否可以正常启动。
You probably might be missing the right PATH for finding all the DLLs required by the service. Usually the service gets installed as a 'LocalSystem' service so you need to add the PATH to the System (and not to User).
Try adding c:\python27 (or whatever the path to your python dlls is) to the SYSTEM PATH, restart the computer and check if it now starts fine.