Yeah, we run our Python App as a service under Windows.<div><br></div><div>You can look at the open-souce part of our product using <a href="http://trac.sjsoft.com/browser">http://trac.sjsoft.com/browser</a></div><div>If you look into the code you should be able to find some stuff to do with services.</div>

<div><br></div><div>Specficially, look in trunk/j5/src/j5/OS/WinService.py<br><br><div class="gmail_quote">On 19 August 2011 07:00, Stephen Hansen <span dir="ltr"><me+list/<a href="mailto:python@ixokai.io">python@ixokai.io</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div></div><div class="h5">On 8/15/11 9:32 PM, snorble wrote:<br>
> Anyone know of a Python application running as a Windows service in<br>
> production? I'm planning a network monitoring application that runs as<br>
> a service and reports back to the central server. Sort of a heartbeat<br>
> type agent to assist with "this server is down, go check on it" type<br>
> situations.<br>
><br>
> If using Visual Studio and C# is the more reliable way, then I'll go<br>
> that route. I love Python, but everything I read about Python services<br>
> seems to have workarounds ahoy for various situations (or maybe that's<br>
> just Windows services in general?). And there seem to be multiple<br>
> layers of workarounds, since it takes py2exe (or similar) and there<br>
> are numerous workarounds required there, depending on which libraries<br>
> and functionality are being used. Overall, reading about Windows<br>
> services in Python is not exactly a confidence inspiring experience.<br>
> If I knew of a reference example of something reliably running in<br>
> production, I'd feel better than copying and pasting some code from a<br>
> guy's blog.<br>
<br>
</div></div>Belatedly: I run a few quite major windows services which are installed<br>
at various customer sites in production, and we have no issues with it<br>
being a windows service.<br>
<br>
I basically only ever ran into two problems:<br>
<br>
 1. The lack of a console. Your service flat out /does not have/ a<br>
console, which is a slightly weird state to be in: writing to sys.stdout<br>
will fail. A print statement left in can crash things up -- even if in<br>
third-party code.<br>
<br>
    Now, once you realize this is there, its easy to "fix". I end up<br>
doing something like this very early on in processing:<br>
<br>
    class FakeFile:<br>
        def __init__(self, fp):<br>
            self._fp = fp<br>
        def write(self, data):<br>
            try:<br>
                self._fp.write(data)<br>
            except:<br>
                pass<br>
<br>
        # repeat with flush()<br>
<br>
    sys.stdout = FakeFile(sys.stdout)<br>
    sys.stderr = FakeFile(sys.stderr)<br>
<br>
    That way it'll run from a regular terminal fine and write out fine,<br>
but if any stray attempts to print are left in, things will pass through<br>
fine when its running as a service.<br>
<br>
  2. Importing modules with the same names as dlls in system32 can go<br>
awry. I don't know if this is still there, I last touched this part of<br>
our code a long, long, long time ago: but my service does some manual<br>
PATH / PYTHONHOME / PYTHONPATH fiddling to take care of it. Its easy<br>
to do.<br>
<br>
It worked fine, and was stable and once going, everything worked fine.<br>
<br>
Ultimately, I have since abandoned running things as a real service<br>
directly, and wrote a "Metaservice" application we use in our company<br>
instead. It runs as a service, and executes any random series of<br>
programs beneath it, creating JOB's for each so any subprocesses of they<br>
launch all get killed together cleanly, and handling dependencies via<br>
between them through various means, and stuff like that. I just got<br>
tired of dealing with windows stuff, so. :)<br>
<font color="#888888"><br>
--<br>
<br>
   Stephen Hansen<br>
   ... Also: Ixokai<br>
   ... Mail: me+list/python (AT) ixokai (DOT) io<br>
   ... Blog: <a href="http://meh.ixokai.io/" target="_blank">http://meh.ixokai.io/</a><br>
<br>
</font><br>--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
<br></blockquote></div><br></div>