Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nativePipeTestService.py 2.1KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # This is an example of a service hosted by python.exe rather than
  2. # pythonservice.exe.
  3. # Note that it is very rare that using python.exe is a better option
  4. # than the default pythonservice.exe - the latter has better error handling
  5. # so that if Python itself can't be initialized or there are very early
  6. # import errors, you will get error details written to the event log. When
  7. # using python.exe instead, you are forced to wait for the interpreter startup
  8. # and imports to succeed before you are able to effectively setup your own
  9. # error handling.
  10. # So in short, please make sure you *really* want to do this, otherwise just
  11. # stick with the default.
  12. import os
  13. import sys
  14. import servicemanager
  15. import win32serviceutil
  16. from pipeTestService import TestPipeService
  17. class NativeTestPipeService(TestPipeService):
  18. _svc_name_ = "PyNativePipeTestService"
  19. _svc_display_name_ = "Python Native Pipe Test Service"
  20. _svc_description_ = "Tests Python.exe hosted services"
  21. # tell win32serviceutil we have a custom executable and custom args
  22. # so registration does the right thing.
  23. _exe_name_ = sys.executable
  24. _exe_args_ = '"' + os.path.abspath(sys.argv[0]) + '"'
  25. def main():
  26. if len(sys.argv) == 1:
  27. # service must be starting...
  28. print("service is starting...")
  29. print("(execute this script with '--help' if that isn't what you want)")
  30. # for the sake of debugging etc, we use win32traceutil to see
  31. # any unhandled exceptions and print statements.
  32. import win32traceutil
  33. print("service is still starting...")
  34. servicemanager.Initialize()
  35. servicemanager.PrepareToHostSingle(NativeTestPipeService)
  36. # Now ask the service manager to fire things up for us...
  37. servicemanager.StartServiceCtrlDispatcher()
  38. print("service done!")
  39. else:
  40. win32serviceutil.HandleCommandLine(NativeTestPipeService)
  41. if __name__ == "__main__":
  42. try:
  43. main()
  44. except (SystemExit, KeyboardInterrupt):
  45. raise
  46. except:
  47. print("Something went bad!")
  48. import traceback
  49. traceback.print_exc()