第二个Python方法没有被调用

时间:2018-01-02 08:18:51

标签: python python-3.x

我是Python的初学者。我准备了下面的脚本来停止并启动一个名为Jenkins的Windows服务。当我运行它时,不执行第二个方法(),即start_service()。请帮忙......

以下是脚本 -

import os
import win32serviceutil

class RestartServices(object):

    serviceName = 'Jenkins'

    def stop_service(self):
        if win32serviceutil.QueryServiceStatus(self.serviceName)[1] == 1:
            print('Service ' + self.serviceName + ' is already stopped.')
        elif win32serviceutil.QueryServiceStatus(self.serviceName)[1] == 4:
            win32serviceutil.StopService(self.serviceName)
            print('Service ' + self.serviceName + ' has been stopped.')

    def start_service(self):
        if win32serviceutil.QueryServiceStatus(self.serviceName)[1] == 4:
            print('Service ' + self.serviceName + ' is already running')
        elif win32serviceutil.QueryServiceStatus(self.serviceName)[1] == 1:
            win32serviceutil.StartService(self.serviceName)
            print('Service ' + self.serviceName + ' has been started...')

obj = RestartServices()
obj.stop_service()
obj.start_service()

0 个答案:

没有答案