pythonservice.exe can't be updated if a python service is already running
zcc0077 opened this issue · comments
Note that issues in this repository are only for bugs or feature requests in the pywin32.
There is a problem, I need to install multiple python script services, I installed the first one is fine, the output is:
Installing service Service1
copying host exe 'C:\Python311\Lib\site-packages\win32\pythonservice.exe' -> 'C:\Python311\pythonservice.exe'
Service installed
When I install another service, I get an error:
Installing service Service2
copying host exe 'C:\Python311\Lib\site-packages\win32\pythonservice.exe' -> 'C:\Python311\pythonservice.exe'
Error installing service: The process cannot access the file because it is being used by another process. (32)
I found that because C:\Python311\pythonservice.exe is occupied by the first service, it cannot be copied successfully. In this case, I can only stop the previous service and then install other services, which will make my service deployment very troublesome (I did not have this problem when using python2 before).
- Steps to reproduce the problem.
Install & start one service and install another service - Version of Python and pywin32
Python 3.11.8 & pywin32-306
The reason this is done is because you might have upgraded pywin32 and trying to use a new pywin32 with an old .exe is going to end badly. An option would be to add a command-line param to the service install code to skip this step, which I'd be happy to take a PR for.
Thanks a lot :), I fixed temporarily by explicitly assign exe to _exe_name_
and no copy action was executed:
class MySrv(win32serviceutil.ServiceFramework):
_svc_name_ = "MySrv"
_svc_display_name_ = "My Service"
_exe_name_ = "C:/Python311/Lib/site-packages/win32/pythonservice.exe"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)