Created
April 16, 2014 16:00
-
-
Save regen100/10898931 to your computer and use it in GitHub Desktop.
Python Windows Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import win32serviceutil | |
class SampleService(win32serviceutil.ServiceFramework): | |
_svc_name_ = 'SampleService' | |
_svc_display_name_ = 'Sample Service' | |
_svc_description_ = 'This is Sample service.' | |
def SvcDoRun(self): | |
self.run = True | |
while self.run: | |
# Write datetime.now() every second | |
import time, datetime | |
time.sleep(1) | |
open(r'C:\test.txt', 'a').write('%s\n' % datetime.datetime.now()) | |
def SvcStop(self): | |
self.run = False | |
if __name__ == '__main__': | |
win32serviceutil.HandleCommandLine(SampleService) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment