Skip to content

Instantly share code, notes, and snippets.

@regen100
Created April 16, 2014 16:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save regen100/10898931 to your computer and use it in GitHub Desktop.
Save regen100/10898931 to your computer and use it in GitHub Desktop.
Python Windows Service
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