[python-win32] Pylons as service...

Tim Roberts timr at probo.com
Mon May 18 19:50:00 CEST 2009


Durumdara wrote:
>
> 1.)
> I wanna ask something about python services.
> ...
> Yesterday I tried to install two of pylons services.
> Interesting thing I saw.
>
> Every of the installed services are have SAME EXE without any
> information to identify, which pylons site is need to start...
> I have never seen same thing before, so I don't understand, which
> information is have PythonService.exe to know which windowsservice.py
> need to start...
>
> Is service name passed to PS.EXE by OS?

Well, yes and no.  Remember that the service script initializes itself. 
It contains all of the code necessary to register itself with the
operating system.  Part of that registration process involves specifying
the exact command line that must be run to start the service.

The service NAME isn't important at all.  That's only used for filing,
so to speak.  It's the command line that identifies the script to be run.


> I saw that in registry the service is have all data it needed. But how
> to know this ONE EXE,  which service started it, and which *.py can it
> use to start?

It's all on the command line that gets registered by the service script.

The exact same thing is true of any long-running Python scripts.  If you
have 10 different normal Python applications running, as far as the
operating system is concerned, all 10 of them are called "python.exe"
(or "pythonw.exe").  If you look in Task Manager, that's exactly what
you'll see.  The personality of the application comes from the script
that is being run, but that's just a data file that gets passed to the
interpreter exe.


> 2.) The service stopping is not correct:
>
> The Python service control handler failed.
>   File "C:\Python25\lib\site-packages\win32\lib\win32serviceutil.py",
> line 791, in ServiceCtrlHandlerEx
>     self.SvcStop()
>   File "c:\web\pylons\xxx\WindowsService.py", line 91, in SvcStop
>     sys.exit()
> <type 'exceptions.SystemExit'>: <NULL>
>
> If I changed it to sys.exit(0), or (1), I also got this message...

Why do you think this is not correct?  You are only seeing that because
you are running this application within a command shell, or some other
environment where you see these log messages.  Ordinarily, if this is
being run as a service in the background, you wouldn't see that message.

It's true that this is not the normal way to stop a service.  You'll see
in that same Pylons script that they have commented out a call to assert
the "stop_event" event, which the SvcDoRun function is blocked on. 
That's the normal way.  SvcStop sets an event, which allows SvcDoRun to
return.  When SvcDoRun returns, the service exits.  However, the
sys.exit method also works.  It's just that you get this little traceback

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list