Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2012-02-26 Thread Mark Hammond

On 23/02/2012 4:36 PM, Kyle wrote:

Bill, did you ever find a resolution to your pythonservice.exe issue?


I've got the PyWin32 extensions installed in a private site-packages
directory under my stuff, which isn't the same as the Python
site-packages site.  I need a way to set PYTHONPATH, or in some other
way initialize the DLL load path and Python sys.path, before running the
pythonservice.exe, don't I?  Otherwise, this load of servicemanager
will fail (and Py_Initialize() will fail if I don't copy
pythonservice.exe to the same location as python.exe and python26.dll).


I have the same requirement.  I need to be able to package up a private copy
of python and pywin32 under my own  directory.

I'm trying Mark's PyNativePipeTestService script, but I receive the same
error (WinXP):

[SC] StartService FAILED 1053:
The service did not respond to the start or control request in a timely
fashion.


In my experience, this simply means the service just failed.  I'd 
suggest checking the event log and/or using the win32trace module to try 
and see what is going on.


Mark
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2012-02-23 Thread Bill Tutt
Well, I know this isn't a solution per say, but the usual cause of this
error message is that you failed to call the Win32 API  SetServiceStatus()
with a 'ask me again in x time' or 'i've finished starting successfully'
call in a fairly quick manner. See
http://msdn.microsoft.com/en-us/library/windows/desktop/ms686241(v=vs.85).aspx
for
more information.

Could python.exe take longer to transition into SERVICE_RUNNING than
pythonservice.exe? I don't know. It wouldn't hurt to pre-generate .pyc or
.pyos to speed up the process.

win32serviceutil.ServiceFramework.ReportServiceStatus(win32service.SERVICE_START_PENDING,
waitHint=2) might be worth calling during your ServiceFramework
subclass __init__ maybe?
Once your SvcDoRun method has been called ReportServiceStatus has been
called with SERVICE_RUNNING for you.

Another thing to watch out for is that SvcStop/SvcShutdown should call
ReportServiceStatus with SERVICE_STOP_PENDING and a waitHint you're
comfortable with. Otherwise, the SCM might kill your service prematurely.
I've seen this happen on Win2k8 R2 for example.

SvcInterrogate appears to like lying to the SCM, but that seems like a bad
idea. :) (it always returns SERVICE_RUNNING)

Bill

On Thu, Feb 23, 2012 at 12:36 AM, Kyle kyle.fla...@gmail.com wrote:


 [SC] StartService FAILED 1053:
 The service did not respond to the start or control request in a timely
 fashion.


___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2012-02-22 Thread Kyle
Bill, did you ever find a resolution to your pythonservice.exe issue?

I've got the PyWin32 extensions installed in a private site-packages
directory under my stuff, which isn't the same as the Python
site-packages site.  I need a way to set PYTHONPATH, or in some other
way initialize the DLL load path and Python sys.path, before running the
pythonservice.exe, don't I?  Otherwise, this load of servicemanager
will fail (and Py_Initialize() will fail if I don't copy
pythonservice.exe to the same location as python.exe and python26.dll). 

I have the same requirement.  I need to be able to package up a private copy
of python and pywin32 under my own  directory.

I'm trying Mark's PyNativePipeTestService script, but I receive the same
error (WinXP):

[SC] StartService FAILED 1053:
The service did not respond to the start or control request in a timely
fashion. 



--
View this message in context: 
http://python.6.n6.nabble.com/Running-a-Windows-Python-service-without-pythonservice-exe-tp1956976p4497536.html
Sent from the Python - python-win32 mailing list archive at Nabble.com.
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-14 Thread Bill Janssen
Mark Hammond skippy.hamm...@gmail.com wrote:

 On 13/05/2010 9:25 AM, Bill Janssen wrote:
  Mark Hammondskippy.hamm...@gmail.com  wrote:
 
  Execute 'python nativePipeTestService.py install' to install it, then
  start it as normal (ie, don't run it manually with no args).
 
  Yes, that's what I tried first.  See my message
  67901.1273677...@parc.com, just previous to the one you replied to.
 
 Sorry - I missed that 'install' command in that message.
 
  $ sc start PyNativePipeTestService
  [SC] StartService FAILED 1053:
 
  The service did not respond to the start or control request in a timely 
  fashion.
 
  $
 
  Same thing if I try to start it from the System Management GUI tool.
 
 I'm not sure what the problem could be.  It appears Python is finding
 all the modules OK and I can't think of why the service request would
 be failing.  Does the standard old pipeTestService.py still work for
 you?

No, it fails the same way.  Is there a test suite for PyWin32 that I
could run to verify my installation is good?

Bill
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-14 Thread Mark Hammond

On 15/05/2010 5:06 AM, Bill Janssen wrote:

Mark Hammondskippy.hamm...@gmail.com  wrote:


On 13/05/2010 9:25 AM, Bill Janssen wrote:

Mark Hammondskippy.hamm...@gmail.com   wrote:


Execute 'python nativePipeTestService.py install' to install it, then
start it as normal (ie, don't run it manually with no args).


Yes, that's what I tried first.  See my message
67901.1273677...@parc.com, just previous to the one you replied to.


Sorry - I missed that 'install' command in that message.


$ sc start PyNativePipeTestService
[SC] StartService FAILED 1053:

The service did not respond to the start or control request in a timely fashion.

$

Same thing if I try to start it from the System Management GUI tool.


I'm not sure what the problem could be.  It appears Python is finding
all the modules OK and I can't think of why the service request would
be failing.  Does the standard old pipeTestService.py still work for
you?


No, it fails the same way.  Is there a test suite for PyWin32 that I
could run to verify my installation is good?


win32\test\testall.py is probably the closest, but it only checks the 
pywin32 implementation and doesn't do much in the way of 'environment' 
checking - indeed, nothing related to services is automatically tested 
at all.


It might be worth checking your windows event log - pythonservice may 
have written something there...


Mark
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-12 Thread Mark Hammond
test
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-12 Thread Mark Hammond
test
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-12 Thread Mark Hammond
test
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-12 Thread Mark Hammond

On 12/05/2010 4:51 PM, Mark Hammond wrote:

test


Oops - sorry about the noise :(

One-of-the-risks-when-working-on-email-clients ly,

Mark
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-12 Thread Bill Janssen
Mark Hammond mhamm...@skippinet.com.au wrote:

 See attached sample which works for me - be sure to place it in the
 same directory as the pipeTestService.py sample (win32/Demos/service).

All right, I put it in a file called nativePipeTestService.py, in that
directory, and tried it.  Here's what I get:

$ pwd -W
c:/UpLib/1.7.9/python/Lib/site-packages/win32/Demos/service
$ python nativePipeTestService.py install
Installing service PyNativePipeTestService
Service installed
$ sc query PyNativePipeTestService

SERVICE_NAME: PyNativePipeTestService
TYPE   : 10  WIN32_OWN_PROCESS 
STATE  : 1  STOPPED 
(NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
WIN32_EXIT_CODE: 1077   (0x435)
SERVICE_EXIT_CODE  : 0  (0x0)
CHECKPOINT : 0x0
WAIT_HINT  : 0x0
$ sc qc PyNativePipeTestService
[SC] GetServiceConfig SUCCESS

SERVICE_NAME: PyNativePipeTestService
TYPE   : 10  WIN32_OWN_PROCESS 
START_TYPE : 3   DEMAND_START
ERROR_CONTROL  : 1   NORMAL
BINARY_PATH_NAME   : c:\UpLib\1.7.9\python\python.exe 
c:\UpLib\1.7.9\python\Lib\site-packages\win32\Demos\service\nativePipeTestService.py
  
LOAD_ORDER_GROUP   :   
TAG: 0  
DISPLAY_NAME   : Python Native Pipe Test Service  
DEPENDENCIES   :   
SERVICE_START_NAME : LocalSystem  
$ python nativePipeTestService.py start
Starting service PyNativePipeTestService []
Error starting service: The service did not respond to the start or control 
request in a timely fashion.
$

What should I try next?

Bill
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-12 Thread Bill Janssen
Bill Janssen jans...@parc.com wrote:

 $ python nativePipeTestService.py start
 Starting service PyNativePipeTestService []
 Error starting service: The service did not respond to the start or control 
 request in a timely fashion.
 $

I rebooted and tried again, same result.

Then I tried setting up a win32trace window first, and ran

$ python nativePipeTestService.py
Redirecting output to win32trace remote collector
$

What shows up in the trace window is this:

 C:\UpLib\1.7.9\python\Lib\site-packages\win32\libpython win32traceutil.py
Collecting Python Trace Output...
service is starting...
(execute this script with '--help' if that isn't what you want)
Something went bad!
Traceback (most recent call last):
  File nativePipeTestService.py, line 51, in module
main()
  File nativePipeTestService.py, line 44, in main
servicemanager.StartServiceCtrlDispatcher()
error: (1063, 'StartServiceCtrlDispatcher', 'The service process could not 
connect to the service controller.')

This smacks of a registry problem, but I'm unsure where to go from here...

Bill
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-12 Thread Mark Hammond

On 13/05/2010 2:08 AM, Bill Janssen wrote:

Bill Janssenjans...@parc.com  wrote:


$ python nativePipeTestService.py start
Starting service PyNativePipeTestService []
Error starting service: The service did not respond to the start or control 
request in a timely fashion.
$


I rebooted and tried again, same result.

Then I tried setting up a win32trace window first, and ran

$ python nativePipeTestService.py
Redirecting output to win32trace remote collector
$

What shows up in the trace window is this:


C:\UpLib\1.7.9\python\Lib\site-packages\win32\libpython win32traceutil.py

Collecting Python Trace Output...
service is starting...
(execute this script with '--help' if that isn't what you want)
Something went bad!
Traceback (most recent call last):
   File nativePipeTestService.py, line 51, inmodule
 main()
   File nativePipeTestService.py, line 44, in main
 servicemanager.StartServiceCtrlDispatcher()
error: (1063, 'StartServiceCtrlDispatcher', 'The service process could not 
connect to the service controller.')

This smacks of a registry problem, but I'm unsure where to go from here...


When run with no args, the program assumes it is being started as the 
service - see the first 3 output lines.


Execute 'python nativePipeTestService.py install' to install it, then 
start it as normal (ie, don't run it manually with no args).  If you 
want different cmdline behaviour, the script can be re-worked to catch 
the error calling StartServiceCtrlDispatcher(), assume the user is 
running it interactively and take some different action.


Mark
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-12 Thread Bill Janssen
Mark Hammond skippy.hamm...@gmail.com wrote:

 Execute 'python nativePipeTestService.py install' to install it, then
 start it as normal (ie, don't run it manually with no args).

Yes, that's what I tried first.  See my message
67901.1273677...@parc.com, just previous to the one you replied to.

$ sc start PyNativePipeTestService
[SC] StartService FAILED 1053:

The service did not respond to the start or control request in a timely fashion.

$

Same thing if I try to start it from the System Management GUI tool.

Bill
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-12 Thread Mark Hammond

On 13/05/2010 9:25 AM, Bill Janssen wrote:

Mark Hammondskippy.hamm...@gmail.com  wrote:


Execute 'python nativePipeTestService.py install' to install it, then
start it as normal (ie, don't run it manually with no args).


Yes, that's what I tried first.  See my message
67901.1273677...@parc.com, just previous to the one you replied to.


Sorry - I missed that 'install' command in that message.


$ sc start PyNativePipeTestService
[SC] StartService FAILED 1053:

The service did not respond to the start or control request in a timely fashion.

$

Same thing if I try to start it from the System Management GUI tool.


I'm not sure what the problem could be.  It appears Python is finding 
all the modules OK and I can't think of why the service request would be 
failing.  Does the standard old pipeTestService.py still work for you?


Mark
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-11 Thread Mark Hammond

On 11/05/2010 12:50 PM, Bill Janssen wrote:

Mark Hammondskippy.hamm...@gmail.com  wrote:


That's correct.  Using python.exe as the host will involve having a
.py script which imports the servicemanager module then call
PrepareToHostSingle and instantiate the service class - or something
like that :)


How definitive :-).  I'm already generating a python script for each
service, so this could easily be incorporated, if I knew exactly what it
was I have to do.

1.  Set up the sys.path and os.environ[Path] properly.

2.  import servicemanager

3.  define my class

4.  call servicemanager.PrepareToHostSingle(my class name)

Seem right?


Sounds about right - but reading pythonservice.cpp is really the 
definitive source to what needs to be done.  Sadly I can't find anything 
more specific, such as a sample.



Another alternative is to ship a slightly modified pythonxx.dll - it
has a feature where a certain string resource contains the basename of
the registry key used at runtime to load the pythonpath - eg, you will
find the resource has 2.6 for Python 2.6 builds.  Using a resource
editor (or even a script using pywin32) to change this to some custom
value will mean the pythonpath can be loaded from a private key in the
registry, meaning you still get isolation from other installed Python
versions.


I could do that, I guess.  I'd like to be able to script all the
preparations, so if it's a GUI step that would be a Bad Thing.  But a
script using pywin32 would be great.  So, I need to know a couple of
things:

1.  What's the name of this certain string resource?

2.  How would one write such a pywin32 script :-)?

I wrote this script to answer question #1:

-
import sys, os

import win32api, win32con

handle = win32api.LoadLibrary(sys.argv[1])
for rname in win32api.EnumResourceNames(handle, win32con.RT_STRING):
 rvalue = win32api.LoadResource(handle, win32con.RT_STRING, rname)
 print rname, rvalue
-

$ python resource.py python26.dll
63 
^...@^@^...@^@^...@^@^...@^@^...@^@^...@^@^...@^@^...@^@^...@2^@@6^@^...@^@^...@^@^...@^@^...@^@^...@^@^...@^@^...@^@
$

So, the name is 63, and it's a 38-byte value with a lot of nul
characters in it.  I'm unsure of just how to hack it with UpdateResource
-- do I just center the replacement text and pad with nul characters?
And what's the registry key this works against, anyway?  I'd have to
update that as part of my installer, too.


I think the above loaded a string *table*.  The resource ID is 1000, and 
py2exe has some code to deal with updating this for a file.  It does:


from py2exe.resources.StringTables import StringTable, RT_STRING
from py2exe_util import add_resource, load_resource
from py2exe.resources.VersionInfo import RT_VERSION

...
# OK - do the strings.
s = StringTable()
# 1000 is the resource ID Python loads for its winver.
s.add_string(1000, new_winver)
for id, data in s.binary():
add_resource(ensure_unicode(dll_name), data, RT_STRING, id, 
False)


While this could be done with pywin32 and the win32api.UpdateResource 
function, that would probably require some struct magic - the 
StringTable object in py2exe hides some of this from you.


HTH,

Mark
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-11 Thread Bill Janssen
Thanks, Mark.

I suppose I could run regsetup.py, but that would make my private Python
globally known, not really what I want to do.

I'll soldier on with option (a), using python.exe to run the service,
and see if I can get that to work on a simple example.

Bill
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-11 Thread Bill Janssen
Mark Hammond mhamm...@skippinet.com.au wrote:

 Sounds about right - but reading pythonservice.cpp is really the
 definitive source to what needs to be done.  Sadly I can't find
 anything more specific, such as a sample.

OK.  pythonservice.exe has a lot of stuff in it -- for instance, there
seems to be a standalone implementation of servicemanager.

And don't I have to hack InstallService somewhere, too?  Otherwise the
Service Manager will try to use PythonService.exe instead of python.exe,
won't it?

A simple example would sure be a help :-).

Bill
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-11 Thread Bill Janssen
OK, so I wrote my own InstallService:


import sys, os, win32service

def InstallService(pythonClassFile, serviceName, displayName,
   startType = None, errorControl = None, bRunInteractive = 0,
   serviceDeps = None, userName = None, password = None,
   exeArgs = None, description = None):

# Handle the default arguments.
if startType is None:
startType = win32service.SERVICE_DEMAND_START
serviceType = win32service.SERVICE_WIN32_OWN_PROCESS
if bRunInteractive:
serviceType = serviceType | win32service.SERVICE_INTERACTIVE_PROCESS
if errorControl is None:
errorControl = win32service.SERVICE_ERROR_NORMAL

pythonClassFile = os.path.abspath(pythonClassFile)
commandLine = '%s %s' % (sys.executable, pythonClassFile)
if exeArgs:
commandLine = commandLine +   + exeArgs
hscm = 
win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS)
try:
hs = win32service.CreateService(
hscm,
serviceName,
displayName,
win32service.SERVICE_ALL_ACCESS, # desired access
serviceType,# service type
startType,
errorControl,   # error control type
commandLine,
None,
0,
serviceDeps,
userName,
password)
if description is not None:
try:

win32service.ChangeServiceConfig2(hs,win32service.SERVICE_CONFIG_DESCRIPTION,description)
except NotImplementedError:
pass## ChangeServiceConfig2 and description do not exist on 
NT
win32service.CloseServiceHandle(hs)
finally:
win32service.CloseServiceHandle(hscm)

if __name__ == __main__:
if len(sys.argv)  1 and os.path.exists(sys.argv[1]):
InstallService(sys.argv[1], os.path.basename(sys.argv[1]), 
os.path.basename(sys.argv[1]))


Note that it doesn't try to register the class string.  Seems to work:

$ python myinstallservice.py test2.py
$ sc query test2.py

SERVICE_NAME: test2.py
TYPE   : 10  WIN32_OWN_PROCESS 
STATE  : 1  STOPPED 
(NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
WIN32_EXIT_CODE: 0  (0x0)
SERVICE_EXIT_CODE  : 0  (0x0)
CHECKPOINT : 0x0
WAIT_HINT  : 0x0
$ sc qc test2.py
[SC] GetServiceConfig SUCCESS

SERVICE_NAME: test2.py
TYPE   : 10  WIN32_OWN_PROCESS 
START_TYPE : 3   DEMAND_START
ERROR_CONTROL  : 1   NORMAL
BINARY_PATH_NAME   : c:\UpLib\1.7.9\python\python.exe 
c:\testrepo2\overhead\test2.py  
LOAD_ORDER_GROUP   :   
TAG: 0  
DISPLAY_NAME   : test2.py  
DEPENDENCIES   :   
SERVICE_START_NAME : LocalSystem  
$

Although I think I should be crunching those paths to the short form.

However, it doesn't start:

$ sc start test2.py
[SC] StartService FAILED 1053:

The service did not respond to the start or control request in a timely fashion.
$

Here's what's in test2.py:


import win32serviceutil
import win32service
import win32event
import win32evtlogutil
import servicemanager

class MyService(win32serviceutil.ServiceFramework):

   _svc_name_ = test2.py
   _svc_display_name_ = test2.py

   def __init__(self, args):
   win32serviceutil.ServiceFramework.__init__(self, args)
   self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

   def SvcStop(self):
   self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
   win32event.SetEvent(self.hWaitStop)

   def SvcDoRun(self):
   servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
 servicemanager.PYS_SERVICE_STARTING,
 (self._svc_name_, ))
   while True:
   win32event.WaitForSingleObject(self.hWaitStop, 500)

servicemanager.Initialize()
servicemanager.PrepareToHostSingle(MyService)
win32serviceutil.HandleCommandLine(MyService)


What am I missing here?

Bill
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-11 Thread Mark Hammond

On 12/05/2010 4:28 AM, Bill Janssen wrote:

OK, so I wrote my own InstallService:


That actually isn't necessary - the class can provide _exe_name_ and 
_exe_args_ attributes to override the defaults.


See attached sample which works for me - be sure to place it in the same 
directory as the pipeTestService.py sample (win32/Demos/service).  I'm 
afraid I did mislead you a little in the steps necessary to get things 
going, but I'm checking this sample into pywin32 so it doesn't get lost 
again :)


Cheers,

Mark
# This is an example of a service hosted by python.exe rather than 
# pythonservice.exe.

# Note that it is very rare that using python.exe is a better option
# than the default pythonservice.exe - the latter has better error handling
# so that if Python itself can't be initialized or there are very early
# import errors, you will get error details written to the event log.  When
# using python.exe instead, you are forced to wait for the interpreter startup
# and imports to succeed before you are able to effectively setup your own
# error handling.

# So in short, please make sure you *really* want to do this, otherwise just
# stick with the default.

import sys
import os
import win32serviceutil
import servicemanager

from pipeTestService import TestPipeService

class NativeTestPipeService(TestPipeService):
_svc_name_ = PyNativePipeTestService
_svc_display_name_ = Python Native Pipe Test Service
_svc_description_ = Tests Python.exe hosted services
# tell win32serviceutil we have a custom executable and custom args
# so registration does the right thing.
_exe_name_ = sys.executable
_exe_args_ = '' + os.path.abspath(sys.argv[0]) + ''

def main():
if len(sys.argv)==1:
# service must be starting...
# for the sake of debugging etc, we use win32traceutil to see
# any unhandled exceptions and print statements.
import win32traceutil
print service is starting...
print (execute this script with '--help' if that isn't what you want)

servicemanager.Initialize()
servicemanager.PrepareToHostSingle(NativeTestPipeService)
# Now ask the service manager to fire things up for us...
servicemanager.StartServiceCtrlDispatcher()
print service done!
else:
win32serviceutil.HandleCommandLine(NativeTestPipeService)

if __name__=='__main__':
try:
main()
except (SystemExit, KeyboardInterrupt):
raise
except:
print Something went bad!
import traceback
traceback.print_exc()
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-10 Thread Mark Hammond

On 10/05/2010 7:08 AM, Bill Janssen wrote:

A few weeks ago, Mark mentioned that there's now a way to run a Windows
service without pythonservice.exe.

I'd like to hear more about that.  Right now, I'm stuck with my UpLib
system on Windows.  I'd like to be able to install everything in the
UpLib directory, including a private copy of Python and PyWin32.  But
then there's no way to tell pythonservice.exe where the modules are, and
so Python services don't start.

I'm thinking the problem is this code in PythonService.cpp:

// Our EXE entry point.
  1540
  1541 int _tmain(int argc, TCHAR **argv)
  1542 {
  1543  PyObject *module, *f;
  1544  PyThreadState *threadState;
  1545  HMODULE hmod;
  1546  FARPROC proc;
  1547  Py_Initialize();
  1548  PyEval_InitThreads();
  1549  module = PyImport_ImportModule(servicemanager);
  1550  if (!module) goto failed;

I've got the PyWin32 extensions installed in a private site-packages
directory under my stuff, which isn't the same as the Python
site-packages site.  I need a way to set PYTHONPATH, or in some other
way initialize the DLL load path and Python sys.path, before running the
pythonservice.exe, don't I?  Otherwise, this load of servicemanager
will fail (and Py_Initialize() will fail if I don't copy
pythonservice.exe to the same location as python.exe and python26.dll).


That's correct.  Using python.exe as the host will involve having a .py 
script which imports the servicemanager module then call 
PrepareToHostSingle and instantiate the service class - or something 
like that :)


Another alternative is to ship a slightly modified pythonxx.dll - it has 
a feature where a certain string resource contains the basename of the 
registry key used at runtime to load the pythonpath - eg, you will find 
the resource has 2.6 for Python 2.6 builds.  Using a resource editor 
(or even a script using pywin32) to change this to some custom value 
will mean the pythonpath can be loaded from a private key in the 
registry, meaning you still get isolation from other installed Python 
versions.


HTH,

Mark


Bill
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Running a Windows Python service without pythonservice.exe?

2010-05-10 Thread Bill Janssen
Mark Hammond skippy.hamm...@gmail.com wrote:

 That's correct.  Using python.exe as the host will involve having a
 .py script which imports the servicemanager module then call
 PrepareToHostSingle and instantiate the service class - or something
 like that :)

How definitive :-).  I'm already generating a python script for each
service, so this could easily be incorporated, if I knew exactly what it
was I have to do.

1.  Set up the sys.path and os.environ[Path] properly.

2.  import servicemanager

3.  define my class

4.  call servicemanager.PrepareToHostSingle(my class name)

Seem right?

 Another alternative is to ship a slightly modified pythonxx.dll - it
 has a feature where a certain string resource contains the basename of
 the registry key used at runtime to load the pythonpath - eg, you will
 find the resource has 2.6 for Python 2.6 builds.  Using a resource
 editor (or even a script using pywin32) to change this to some custom
 value will mean the pythonpath can be loaded from a private key in the
 registry, meaning you still get isolation from other installed Python
 versions.

I could do that, I guess.  I'd like to be able to script all the
preparations, so if it's a GUI step that would be a Bad Thing.  But a
script using pywin32 would be great.  So, I need to know a couple of
things:

1.  What's the name of this certain string resource?

2.  How would one write such a pywin32 script :-)?

I wrote this script to answer question #1:

-
import sys, os

import win32api, win32con

handle = win32api.LoadLibrary(sys.argv[1])
for rname in win32api.EnumResourceNames(handle, win32con.RT_STRING):
rvalue = win32api.LoadResource(handle, win32con.RT_STRING, rname)
print rname, rvalue
-

$ python resource.py python26.dll
63 
^...@^@^...@^@^...@^@^...@^@^...@^@^...@^@^...@^@^...@^@^...@2^@@6^@^...@^@^...@^@^...@^@^...@^@^...@^@^...@^@^...@^@
$

So, the name is 63, and it's a 38-byte value with a lot of nul
characters in it.  I'm unsure of just how to hack it with UpdateResource
-- do I just center the replacement text and pad with nul characters?
And what's the registry key this works against, anyway?  I'd have to
update that as part of my installer, too.

Bill
___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32