[python-win32] How to determine whether program running as
service?
David Rushby
davidrushby at yahoo.com
Thu Sep 9 17:20:56 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.
Why not something like this:
servicemanager.RunningAsService() -> bool
A RunningAsService predicate would keep the functionality grouped with
other service-related predicates (e.g., servicemanager.Debugging)),
would be ultra-simple for client code, and would encapsulate the
service-mode-detection logic, insulating it from radical future changes
of the sort that occurred between builds 1xx and 2xx.
My previous needToReplaceStdStreams code could become as simple (and
readable) as:
------------------------------------------------
import servicemanager
needToReplaceStdStreams = servicemanager.RunningAsService() and not
servicemanager.Debugging()
------------------------------------------------
> That doesn't help you now though.
Actually, it would; this issue alone has prevented me from migrating to
pywin32 >= 200.
__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail
More information about the Python-win32
mailing list