Windows service in production?

aspineux aspineux at gmail.com
Tue Aug 16 08:55:54 EDT 2011


On Aug 16, 6:32 am, snorble <snor... at 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.




More information about the Python-list mailing list