Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Windows service in production?

Reply
Thread Tools

Windows service in production?

 
 
snorble
Guest
Posts: n/a
 
      08-16-2011
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.
 
Reply With Quote
 
 
 
 
Tim Golden
Guest
Posts: n/a
 
      08-16-2011
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
 
Reply With Quote
 
 
 
 
alex23
Guest
Posts: n/a
 
      08-16-2011
snorble <(E-Mail Removed)> 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.
 
Reply With Quote
 
aspineux
Guest
Posts: n/a
 
      08-16-2011
On Aug 16, 6:32*am, snorble <(E-Mail Removed)> 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/tc...r#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.


 
Reply With Quote
 
snorble
Guest
Posts: n/a
 
      08-16-2011
On Aug 16, 2:52*am, Tim Golden <(E-Mail Removed)> 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?
 
Reply With Quote
 
Tim Golden
Guest
Posts: n/a
 
      08-17-2011
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
 
Reply With Quote
 
Chris Gonnerman
Guest
Posts: n/a
 
      08-18-2011
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/proje...intserver.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.
 
Reply With Quote
 
Grummble
Guest
Posts: n/a
 
      08-19-2011
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/...rvices-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.



 
Reply With Quote
 
Chris Gonnerman
Guest
Posts: n/a
 
      08-19-2011
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/proje...intserver.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.
 
Reply With Quote
 
Stephen Hansen
Guest
Posts: n/a
 
      08-19-2011
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/


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.10 (Darwin)

iQEcBAEBAgAGBQJOTe3uAAoJEKcbwptVWx/lYOsIAKAQaLdPV8a9Xc0PWg3rl+wr
r9tPwROo/kF64jtSqPT6SfYho47HbzqEYi19fckSMTJRteraSbbdaAY301p C0Buj
4nOzw7tRC+ZCVnbXlNgnSyerSOft+DiHJsar15fdEDe48T45yv UOAPXKElI6C1ho
16K4Z9x5jXTejRmOpWSoi1eVfLyS+vsebamC1+SN4GKF+5ds9I vXbrP24E5oOKgC
eP8pVCilwEiGEuylxpg++Y9pOxYYQ8opXgZZprvWqUjCyILmPd gLip1uvLsdx2KK
Dc1C0YnF6jQzn+hnXqK7AsU18nNvBEQ3ijoVMnt0urun3+HiLa J109syWW60+i8=
=y/7t
-----END PGP SIGNATURE-----

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ajax calls web service in wcf(windows service) Billy Zhang ASP .Net 7 07-31-2008 07:37 AM
How to control Windows Service through Web Service prowyh ASP .Net 0 11-16-2007 04:05 AM
Indexing services under Windows XP SP2 - Can I disable MS Indexing Service to hasten Google's OR does Google Desktop uses this MS Indexing Service? ricardodefaria Computer Support 6 08-05-2007 04:14 AM
Exposing Unmanaged C++ Windows Service code as a ASP.NET service. =?Utf-8?B?c2h5YW0=?= ASP .Net 2 05-22-2006 01:47 AM
InvocationTargetException when calling "new Service()" in Axis web service to call another web service Michael Averstegge Java 0 01-10-2006 11:05 PM



Advertisments