Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news2.arglkargh.de!news.wiretrip.org!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'python,': 0.01; 'stuff,': 0.07; 'used.': 0.07; 'python': 0.08; 'also:': 0.09; 'content- type:multipart/signed': 0.09; 'executes': 0.09; 'filename:fname piece:signature': 0.09; 'def': 0.15; '(at)': 0.16; '(dot)': 0.16; 'content-type:application/pgp-signature': 0.16; 'dlls': 0.16; 'except:': 0.16; 'filename:fname piece:asc': 0.16; 'filename:fname:signature.asc': 0.16; 'flush()': 0.16; "guy's": 0.16; 'inspiring': 0.16; 'received:209.85.213.174': 0.16; 'received:mail-yx0-f174.google.com': 0.16; 'route.': 0.16; 'sys.stderr': 0.16; 'sys.stdout': 0.16; 'workarounds': 0.16; 'wrote:': 0.16; 'subject:Windows': 0.18; 'slightly': 0.19; 'seems': 0.20; 'wrote': 0.20; 'blog:': 0.21; 'long,': 0.21; 'maybe': 0.21; 'so.': 0.22; 'stuff': 0.22; 'header:In-Reply-To:1': 0.22; 'runs': 0.23; '(or': 0.23; 'fine,': 0.23; 'worked': 0.23; 'pm,': 0.24; 'server.': 0.24; '"this': 0.24; 'in:': 0.24; 'libraries': 0.24; 'code': 0.25; 'creating': 0.25; 'statement': 0.25; 'code.': 0.26; 'fine': 0.26; 'windows': 0.26; "i'm": 0.27; 'random': 0.28; 'server': 0.29; 'pass': 0.29; 'fine.': 0.29; 'importing': 0.29; 'print': 0.29; 'example': 0.30; 'do.': 0.30; 'down,': 0.30; 'hansen': 0.30; 'layers': 0.30; 'means,': 0.30; 'ran': 0.30; 'situations': 0.30; 'class': 0.30; 'modules': 0.31; 'subject:?': 0.31; 'seem': 0.31; 'third-party': 0.32; 'received:24': 0.32; 'handling': 0.32; 'does': 0.32; 'anyone': 0.32; 'installed': 0.32; 'sort': 0.33; 'it.': 0.33; 'there': 0.33; 'to:addr:python-list': 0.33; 'copying': 0.33; '...': 0.34; "i'll": 0.34; 'realize': 0.34; 'quite': 0.34; 'things': 0.34; 'subject:service': 0.34; 'try:': 0.34; 'weird': 0.34; 'reference': 0.35; 'running': 0.35; 'regular': 0.35; 'doing': 0.36; 'skip:" 10': 0.36; 'instead.': 0.37; 'using': 0.37; 'run': 0.37; 'but': 0.37; 'something': 0.37; 'two': 0.37; 'stable': 0.38; 'some': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; "i'd": 0.40; 'more': 0.60; 'your': 0.61; 'company': 0.61; 'central': 0.62; 'love': 0.62; 'services': 0.62; 'assist': 0.62; 'back': 0.62; 'our': 0.63; 'customer': 0.65; 'sites': 0.65; 'ever': 0.65; 'agent': 0.65; 'series': 0.65; 'crash': 0.67; 'dealing': 0.69; 'care': 0.71; 'header:Reply-To:1': 0.71; 'studio': 0.71; 'reply- to:no real name:2**0': 0.71; 'mail:': 0.73; 'numerous': 0.73; 'situations.': 0.73; 'confidence': 0.82; 'beneath': 0.84; 'console,': 0.84; 'going,': 0.84; 'it"': 0.84; 'pasting': 0.84; 'similar)': 0.84; 'ultimately,': 0.84; 'production,': 0.91; 'touched': 0.91; 'killed': 0.93; 'overall,': 0.93; 'url:io': 0.93 Sender: Ixokai Date: Thu, 18 Aug 2011 22:00:30 -0700 From: Stephen Hansen MIME-Version: 1.0 To: python-list@python.org Subject: Re: Windows service in production? References: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> In-Reply-To: <90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com> X-Enigmail-Version: 1.1.1 OpenPGP: id=555B1FE5; url=http://id.ixokai.io/pub.asc Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig2CA8AE02976C95C185D65DF3" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: me+list/python@ixokai.io List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 98 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1313730036 news.xs4all.nl 23859 [2001:888:2000:d::a6]:54163 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11832 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig2CA8AE02976C95C185D65DF3 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 8/15/11 9:32 PM, snorble wrote: > Anyone know of a Python application running as a Windows service in > production? I'm planning a network monitoring application that runs as > a service and reports back to the central server. Sort of a heartbeat > type agent to assist with "this server is down, go check on it" type > situations. >=20 > If using Visual Studio and C# is the more reliable way, then I'll go > that route. I love Python, but everything I read about Python services > seems to have workarounds ahoy for various situations (or maybe that's > just Windows services in general?). And there seem to be multiple > layers of workarounds, since it takes py2exe (or similar) and there > are numerous workarounds required there, depending on which libraries > and functionality are being used. Overall, reading about Windows > services in Python is not exactly a confidence inspiring experience. > If I knew of a reference example of something reliably running in > production, I'd feel better than copying and pasting some code from a > guy's blog. Belatedly: I run a few quite major windows services which are installed at various customer sites in production, and we have no issues with it being a windows service. I basically only ever ran into two problems: 1. The lack of a console. Your service flat out /does not have/ a console, which is a slightly weird state to be in: writing to sys.stdout will fail. A print statement left in can crash things up -- even if in third-party code. Now, once you realize this is there, its easy to "fix". I end up doing something like this very early on in processing: class FakeFile: def __init__(self, fp): self._fp =3D fp def write(self, data): try: self._fp.write(data) except: pass # repeat with flush() sys.stdout =3D FakeFile(sys.stdout) sys.stderr =3D FakeFile(sys.stderr) That way it'll run from a regular terminal fine and write out fine, but if any stray attempts to print are left in, things will pass through fine when its running as a service. 2. Importing modules with the same names as dlls in system32 can go awry. I don't know if this is still there, I last touched this part of our code a long, long, long time ago: but my service does some manual PATH / PYTHONHOME / PYTHONPATH fiddling to take care of it. Its easy to do. It worked fine, and was stable and once going, everything worked fine. Ultimately, I have since abandoned running things as a real service directly, and wrote a "Metaservice" application we use in our company instead. It runs as a service, and executes any random series of programs beneath it, creating JOB's for each so any subprocesses of they launch all get killed together cleanly, and handling dependencies via between them through various means, and stuff like that. I just got tired of dealing with windows stuff, so. :) --=20 Stephen Hansen ... Also: Ixokai ... Mail: me+list/python (AT) ixokai (DOT) io ... Blog: http://meh.ixokai.io/ --------------enig2CA8AE02976C95C185D65DF3 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.10 (Darwin) iQEcBAEBAgAGBQJOTe3uAAoJEKcbwptVWx/lYOsIAKAQaLdPV8a9Xc0PWg3rl+wr r9tPwROo/kF64jtSqPT6SfYho47HbzqEYi19fckSMTJRteraSbbdaAY301pC0Buj 4nOzw7tRC+ZCVnbXlNgnSyerSOft+DiHJsar15fdEDe48T45yvUOAPXKElI6C1ho 16K4Z9x5jXTejRmOpWSoi1eVfLyS+vsebamC1+SN4GKF+5ds9IvXbrP24E5oOKgC eP8pVCilwEiGEuylxpg++Y9pOxYYQ8opXgZZprvWqUjCyILmPdgLip1uvLsdx2KK Dc1C0YnF6jQzn+hnXqK7AsU18nNvBEQ3ijoVMnt0urun3+HiLaJ109syWW60+i8= =y/7t -----END PGP SIGNATURE----- --------------enig2CA8AE02976C95C185D65DF3--