[python-win32] How to determine whether program running as
service?
Mark Hammond
mhammond at skippinet.com.au
Thu Sep 9 06:13:10 CEST 2004
> What's the canonical way to programmatically determine whether a
> pywin32-based Python program is running as a Windows service or as a
> regular process?
I don't see one :( I would be happy to add one - eg, sys.serviceexecutable
being set to the host executable when launched as a service. That doesn't
help you now though.
Hmmm - actually:
is_service = 'servicemanager' in sys.modules
before your import of servicemanager would work - the framework imports this
module before your module. However, that is ugly and just as error prone as
catching the import error was. I agree something canonical and simple would
be good.
> Examining the name of the executable (sys.executable) won't work,
> because Python services don't require that PythonService.exe host them
> (a py2exe-fied service is a good example of a situation in which one
> might not want to use PythonService.exe).
And indeed PythonService.exe may die in later versions - python.exe could
host services directly. That change was made specifically so py2exe can
handle services.
Mark.
More information about the Python-win32
mailing list