Re: pythonservice.exe registration failed used by another process
Mark Hammond <[email protected]> Fri, 26 Apr 2024 09:29:41 -0400
| Newsgroups | gmane.comp.python.windows |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--===============8104864043445202126==
Content-Type: multipart/alternative;
boundary="------------JRof1S8xJ5H3oL8Wndf0vmPm"
Content-Language: en-US
This is a multi-part message in MIME format.
--------------JRof1S8xJ5H3oL8Wndf0vmPm
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
On 2024-04-25 9:29 p.m., Jacob Nolan via python-win32 wrote:
>
> Hi all,
>
> I've been having a reoccurring error across multiple windows installs
> and python versions (3.9.*-3.11.*) when performing an install of a
> python windows service.
>
> This is the result of calling *python service_config.py install *on 3.9.5
>
> The error is:
>
> |*copying host exe
> 'E:\jacobnolan\installed_programs\programs\python39\lib\site-packages\win32\pythonservice.exe'
> -> 'E:\*|*|jacobnolan||\installed_programs\programs\python39\pythonservice.exe'
> Error installing service: The process cannot access the file because
> it is being used by another process. (32)|*
>
> For this system, this is not the first python service I have
> installed. Additionally I've installed multiple services while other
> python services have been running.
>
> As stated in the error it looks to be the destination
> pythonservice.exe is being used by another process, so can't be
> replaced by my installing process.
>
>
> Is there an approach to handle this?
>
> * I'm not sure if pythonservice.exe really needs to be replaced each
> install. I was contemplating looking at the service registration
> process to determine if this step can be skipped.
>
The version of win32serviceutil you linked to isn't the latest, but I
assume you are talking about the copy made just after it prints
`print(f"copying host exe '{maybe}' -> '{correct}'")`? If so, as the
comments note, it doesn't really need to be updated each install, but
win32serviceutil takes a conservative approach because it's difficult to
know whether pywin32 might have been upgraded. The simplest way to avoid
that copy is to just remove the "maybe" file, leaving the "correct" file
in-place. I'd be fine with a patch that catches an error making the
copy, prints a warning but then continues. It might even be better if
that script tried to *move* the file - that should mean that upgrades
would still attempt to update it, but otherwise the file is only updated
once.
> *
>
>
> * Or if I should specify the location of the pythonservice.exe now
> it is in the correct location to access the appropriate DLL's?
> e.g win32serviceutil service use exeName?
> o https://github.com/mhammond/pywin32/blob/fcab71452cc8aefeb23b897a03753e34298d555f/win32/Lib/win32serviceutil.py#L215
>
In your other email you mentioned trying to use pyinstaller or similar
to package your service - in that world then you almost certainly will
want to point it at your own executable, although then you probably just
want sys.executable, in which case sys.frozen being set is all you need.
HTH,
Mark
--------------JRof1S8xJ5H3oL8Wndf0vmPm
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 2024-04-25 9:29 p.m., Jacob Nolan
via python-win32 wrote:<br>
</div>
<blockquote type="cite"
cite="mid:0108018f18057507-39c4de94-65c5-447e-82cf-563b20219133-000000@ap-southeast-2.amazonses.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<p>Hi all,</p>
<p>I've been having a reoccurring error across multiple windows
installs and python versions (3.9.*-3.11.*) when performing an
install of a python windows service. <br>
</p>
<p>This is the result of calling <b>python service_config.py
install </b>on 3.9.5<br>
</p>
<p>The error is:<br>
</p>
<div class="moz-signature">
<div class="moz-signature">
<pre><code id="code"><span> <b>copying host exe 'E:\jacobnolan\installed_programs\programs\python39\lib\site-packages\win32\pythonservice.exe' -> 'E:\</b></span></code><b><code
id="code"><span>jacobnolan</span></code><code id="code"><span>\inst</span><span>alled_programs\programs\python39\pythonservice.exe'</span>
<span> Error installing service: The process cannot access the file because it is being used by another process. (32)</span></code></b></pre>
</div>
</div>
<div class="moz-signature"><br>
</div>
<div class="moz-signature">For this system, this is not the first
python service I have installed. Additionally I've installed
multiple services while other python services have been
running. <br>
</div>
<div class="moz-signature"><br>
</div>
<div class="moz-signature">As stated in the error it looks to be
the destination pythonservice.exe is being used by another
process, so can't be replaced by my installing process.<br>
</div>
<div class="moz-signature"><br>
</div>
<div class="moz-signature"><br>
</div>
<div class="moz-signature">Is there an approach to handle this? <br>
</div>
<div class="moz-signature">
<ul>
<li>I'm not sure if pythonservice.exe really needs to be
replaced each install. I was contemplating looking at the
service registration process to determine if this step can
be skipped. <br>
</li>
</ul>
</div>
</blockquote>
<p>The version of win32serviceutil you linked to isn't the latest,
but I assume you are talking about the copy made just after it
prints `print(f"copying host exe '{maybe}' -> '{correct}'")`?
If so, as the comments note, it doesn't really need to be updated
each install, but win32serviceutil takes a conservative approach
because it's difficult to know whether pywin32 might have been
upgraded. The simplest way to avoid that copy is to just remove
the "maybe" file, leaving the "correct" file in-place. I'd be fine
with a patch that catches an error making the copy, prints a
warning but then continues. It might even be better if that script
tried to *move* the file - that should mean that upgrades would
still attempt to update it, but otherwise the file is only updated
once.<br>
</p>
<blockquote type="cite"
cite="mid:0108018f18057507-39c4de94-65c5-447e-82cf-563b20219133-000000@ap-southeast-2.amazonses.com">
<div class="moz-signature">
<ul>
<li> <br>
</li>
<li>Or if I should specify the location of the
pythonservice.exe now it is in the correct location to
access the appropriate DLL's? e.g win32serviceutil service
<span
class="blob-code-inner blob-code-marker js-code-nav-pass js-skip-tagsearch"
data-code-marker="-"><span class="pl-s1 x">use exeName?</span></span></li>
<ul>
<li><span
class="blob-code-inner blob-code-marker js-code-nav-pass js-skip-tagsearch"
data-code-marker="-"><span class="pl-s1 x"><a
class="moz-txt-link-freetext"
href="https://github.com/mhammond/pywin32/blob/fcab71452cc8aefeb23b897a03753e34298d555f/win32/Lib/win32serviceutil.py#L215"
moz-do-not-send="true">https://github.com/mhammond/pywin32/blob/fcab71452cc8aefeb23b897a03753e34298d555f/win32/Lib/win32serviceutil.py#L215</a><br>
</span></span></li>
</ul>
</ul>
</div>
</blockquote>
<p>In your other email you mentioned trying to use pyinstaller or
similar to package your service - in that world then you almost
certainly will want to point it at your own executable, although
then you probably just want sys.executable, in which case
sys.frozen being set is all you need.</p>
<p>HTH,</p>
<p>Mark</p>
<br>
</body>
</html>
--------------JRof1S8xJ5H3oL8Wndf0vmPm--
--===============8104864043445202126==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32
--===============8104864043445202126==--