Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #11504 > unrolled thread

Windows service in production?

Started bysnorble <snorble@hotmail.com>
First post2011-08-15 21:32 -0700
Last post2011-08-18 22:00 -0700
Articles 10 — 7 participants

Back to article view | Back to comp.lang.python


Contents

  Windows service in production? snorble <snorble@hotmail.com> - 2011-08-15 21:32 -0700
    Re: Windows service in production? Tim Golden <mail@timgolden.me.uk> - 2011-08-16 08:52 +0100
      Re: Windows service in production? snorble <snorble@hotmail.com> - 2011-08-16 07:46 -0700
        Re: Windows service in production? Tim Golden <mail@timgolden.me.uk> - 2011-08-17 13:17 +0100
        Re: [Python] Re: Windows service in production? Chris Gonnerman <chris@gonnerman.org> - 2011-08-18 09:30 -0500
        Re: [Python] Re: Windows service in production? Chris Gonnerman <chris@gonnerman.org> - 2011-08-18 22:45 -0500
    Re: Windows service in production? alex23 <wuwei23@gmail.com> - 2011-08-16 01:08 -0700
    Re: Windows service in production? aspineux <aspineux@gmail.com> - 2011-08-16 05:55 -0700
    Re: Windows service in production? Grummble <grrrrr@rrrrr.com> - 2011-08-18 22:24 -0400
    Re: Windows service in production? Stephen Hansen <me+list/python@ixokai.io> - 2011-08-18 22:00 -0700

#11504 — Windows service in production?

Fromsnorble <snorble@hotmail.com>
Date2011-08-15 21:32 -0700
SubjectWindows service in production?
Message-ID<90342eaa-28e2-4a86-9e5c-07299de10435@g9g2000yqb.googlegroups.com>
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.

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.

[toc] | [next] | [standalone]


#11523

FromTim Golden <mail@timgolden.me.uk>
Date2011-08-16 08:52 +0100
Message-ID<mailman.44.1313481167.27778.python-list@python.org>
In reply to#11504
On 16/08/2011 05:32, 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.

Don't know what it'll take to inspire you with confidence, but I have
several Python services running here without a hitch.
The longest have been running for about three years -- not without
a stop, since they have to be restarted for reasons external to the
service itself.

There's no py2exe involved, just the pywin32 service wrappers. (The
apps in question are also set up to run standalone for testing etc.).
They're mostly around a helpdesk system: one app ingests email requests
to the helpdesk; another post-processes call changes, currently to
send out email alerts to interested parties; another triggers alarms
on calls for various purposes, etc.

I don't claim they're the most sophisticated pieces of code on Earth,
but it doesn't sound like you're after anything spectacular either.

TJG

[toc] | [prev] | [next] | [standalone]


#11558

Fromsnorble <snorble@hotmail.com>
Date2011-08-16 07:46 -0700
Message-ID<27ced2ef-7ae8-4b40-b4eb-c9168f369598@w11g2000vbp.googlegroups.com>
In reply to#11523
On Aug 16, 2:52 am, Tim Golden <m...@timgolden.me.uk> wrote:
> On 16/08/2011 05:32, 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.
>
> Don't know what it'll take to inspire you with confidence, but I have
> several Python services running here without a hitch.
> The longest have been running for about three years -- not without
> a stop, since they have to be restarted for reasons external to the
> service itself.
>
> There's no py2exe involved, just the pywin32 service wrappers. (The
> apps in question are also set up to run standalone for testing etc.).
> They're mostly around a helpdesk system: one app ingests email requests
> to the helpdesk; another post-processes call changes, currently to
> send out email alerts to interested parties; another triggers alarms
> on calls for various purposes, etc.
>
> I don't claim they're the most sophisticated pieces of code on Earth,
> but it doesn't sound like you're after anything spectacular either.
>
> TJG

Interesting. Normally I would use py2exe then do "myapp.exe -install"
to install the app as a service. How do you handle installing the
service? Also what does the service show under the properties, for the
executable? "python.exe script.py" or something else?

[toc] | [prev] | [next] | [standalone]


#11678

FromTim Golden <mail@timgolden.me.uk>
Date2011-08-17 13:17 +0100
Message-ID<mailman.125.1313583453.27778.python-list@python.org>
In reply to#11558
On 16/08/2011 15:46, snorble wrote:
> Interesting. Normally I would use py2exe then do "myapp.exe -install"
> to install the app as a service. How do you handle installing the
> service? Also what does the service show under the properties, for the
> executable? "python.exe script.py" or something else?

To install, I simply invoke the Command-line handler which comes with 
the pywin32 service utils:

if __name__ == '__main__':
   win32serviceutil.HandleCommandLine (Service)

(I imagine that's what py2exe's doing for you behind the scenes).

The executable shows as pythonservice.exe. The short and long
display names can of course be whatever you like.

TJG

[toc] | [prev] | [next] | [standalone]


#11756 — Re: [Python] Re: Windows service in production?

FromChris Gonnerman <chris@gonnerman.org>
Date2011-08-18 09:30 -0500
SubjectRe: [Python] Re: Windows service in production?
Message-ID<mailman.163.1313677841.27778.python-list@python.org>
In reply to#11558
Chiming in late here, but I've been running a very simple Python service 
for some time now on a number of computers.  It's my Raw Print Server, 
available at 
http://newcenturycomputers.net/projects/rawprintserver.html, and I have 
instructions on the page for installing the Windows service version.  
It's really quite simple to do in plain Python; the only reason to use 
py2exe is if you don't want to install a full Python interpreter on the 
computer.  But since I generally do anyway, it doesn't matter to me.

-- Chris.

[toc] | [prev] | [next] | [standalone]


#11829 — Re: [Python] Re: Windows service in production?

FromChris Gonnerman <chris@gonnerman.org>
Date2011-08-18 22:45 -0500
SubjectRe: [Python] Re: Windows service in production?
Message-ID<mailman.207.1313725560.27778.python-list@python.org>
In reply to#11558
Chiming in late here, but I've been running a very simple Python service 
for some time now on a number of computers.  It's my Raw Print Server, 
available at 
http://newcenturycomputers.net/projects/rawprintserver.html, and I have 
instructions on the page for installing the Windows service version. 
It's really quite simple to do in plain Python; the only reason to use 
py2exe is if you don't want to install a full Python interpreter on the 
computer.  But since I generally do anyway, it doesn't matter to me.

-- Chris.

[toc] | [prev] | [next] | [standalone]


#11526

Fromalex23 <wuwei23@gmail.com>
Date2011-08-16 01:08 -0700
Message-ID<a06a3f8f-073a-4f5b-ae85-c339bd1463f9@d7g2000vbv.googlegroups.com>
In reply to#11504
snorble <snor...@hotmail.com> wrote:
> 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?).

What workarounds do you mean? Every example I've ever seen makes
direct use of the Windows modules for Python.

> 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.

What about existing code recipes which were featured in the Python
Cookbook?

http://code.activestate.com/recipes/551780/

Not a hint of pyexe or weird hackery.

[toc] | [prev] | [next] | [standalone]


#11550

Fromaspineux <aspineux@gmail.com>
Date2011-08-16 05:55 -0700
Message-ID<77300e22-241d-4b85-9758-680ed8ebbfc7@z17g2000vbp.googlegroups.com>
In reply to#11504
On Aug 16, 6:32 am, snorble <snor...@hotmail.com> 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.

I don't use service for my own python applications, even standalone
py2exe applications.
I use the Windows taskscheduler that start it once and try every
minute to start it again
but is is running all the time, and the the scheduler does nothing and
wait to see for the next minute.
When the python program crash then the scheduler restart it in the
minute.

look here how I do with tcpproxyreflector:
http://blog.magiksys.net/software/tcp-proxy-reflector#tcpr_service

In My MKSBackup  http://blog.magiksys.net/mksbackup-quick-overview
I have a install() function that create the task in the scheduler for
XP and Windows2008

And this code, use a 2 min interval


        print 'create task %s in scheduler' % (task_name, )
        interval=raw_input_with_default('Enter interval in minutes',
'>', str(interval_in_minutes))
        cmd='"%s" -c "%s"' % (os.path.join(install_target,
os.path.basename(sys.argv[0])), os.path.join(target, ini_file))
        schtasks_cmd=[ 'SCHTASKS', '/Create', '/SC', 'MINUTE', '/MO',
interval, '/TN', task_name, '/RU', os.getenv('USERNAME'), '/TR', cmd ]
        if sys.getwindowsversion()[0]>5:
            # under 2008 ? require HIGHEST privilege
            # schtasks_cmd.insert(2, 'HIGHEST')
            # schtasks_cmd.insert(2, '/RL')
            # under 2008, to force the system to ask for the password,
set empty password
            i=schtasks_cmd.index('/RU')+2
            schtasks_cmd.insert(i, '')
            schtasks_cmd.insert(i, '/RP')
        else:
            pass


Mix all 3 source to get what you want.

Services are probably fine too, but this is another story.


>
> 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.

[toc] | [prev] | [next] | [standalone]


#11828

FromGrummble <grrrrr@rrrrr.com>
Date2011-08-18 22:24 -0400
Message-ID<LPj3q.134647$fD6.42559@en-nntp-02.dc1.easynews.com>
In reply to#11504
On 08/16/2011 12:32 AM, 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.
>

I modified something similar to:
http://code.activestate.com/recipes/551780-win-services-helper/
and it was in production for several years without any issues.

Specifically it processed orders generated by a customer's MRP system, 
delivered to us via LPR, then processed into a format our in house 
windows hosted picking/shipping system could digest. Availability was a 
*major* requirement, and it worked flawlessly.


[toc] | [prev] | [next] | [standalone]


#11832

FromStephen Hansen <me+list/python@ixokai.io>
Date2011-08-18 22:00 -0700
Message-ID<mailman.210.1313730036.27778.python-list@python.org>
In reply to#11504

[Multipart message — attachments visible in raw view] — view raw

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.
> 
> 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 = fp
        def write(self, data):
            try:
                self._fp.write(data)
            except:
                pass

        # repeat with flush()

    sys.stdout = FakeFile(sys.stdout)
    sys.stderr = 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. :)

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web