Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pythonservice.exe can't be updated if a python service is already running #2194

Open
zcc0077 opened this issue Mar 6, 2024 · 2 comments
Open

Comments

@zcc0077
Copy link

zcc0077 commented Mar 6, 2024

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
@mhammond
Copy link
Owner

mhammond commented Mar 6, 2024

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.

@mhammond mhammond changed the title Only one service can be created by pywin32 pythonservice.exe can't be updated if a python service is already running Mar 6, 2024
@zcc0077
Copy link
Author

zcc0077 commented Mar 7, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants