-
Notifications
You must be signed in to change notification settings - Fork 104
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
Server.stop() does not kill the java process in Windows #8
Comments
This problem still exists on Windows 7 as described above. |
try proxy.close() prior to the server.stop() that helped me, although if the test fails mid way through it still doesn't close the process. |
Calling proxy.close() prior to server.stop() didn't resolve this issue for me on Windows 7. |
Having the same issue on Mac OS X and Windows Server 2012. This is my workaround:
|
On Debian 8 (not Windows)Python: Selenium v3.0.2, python3.4, browsermobproxy v0.5.0 When run, it will create these two applicable lines in the ps aux: But all of the various suggestions (above) to stop the BMP Server always leave this in the ps aux output: java -Dapp.name=browsermob-proxy -Dbasedir=/usr/local/browsermobproxy -jar /usr/local/browsermobproxy/lib/browsermob-dist-2.1.4.jar --port=8080 I need to get rid of this proc: How? Suggestions? The shutdown code:
Produces this debugging output:
server.log:
bmp.log:
|
Any updates on it? I have the same problem(reproduced on CentOS7 and Ubuntu 16.04) |
It seems I found the issue; |
PR is made(for Linux only since I don't have Windows machine to test a fix for Windows. However, I have on assumption on possible fix(see PR description) |
Why is this marked as closed? The issue is currently present under Windows. |
+1
Could it be windows permission case? |
This can be solved by modifying the stop() method and adding a windows handler like this: import psutil, signal
parent_process = psutil.Process(self.process.pid)
child_process = parent_process.children(recursive=True)
for child in child_process:
child.send_signal(signal.SIGTERM)
try:
parent_process.send_signal(signal.SIGTERM)
except psutil.NoSuchProcess:
pass |
I've investigate this issue deeply. What happens, than when you start browsermobproxy server (I will reffer to it as bmp_daemon, see https://medium.com/@arkadyt/setting-up-programmatic-aws-access-for-mfa-protected-federated-identities-3be22bcecf4b for details) it uses subprocess.Popen with command that contains bat-file. So, what happen on Windows Python process start's cmd that executes bat-file that starts Java process. When you're calling close() function on bmp_daemon, it successfully kills cmd process. On Windows (and on Mac as per #76) OS doesn't kills grand process automatically (I don't know what's happen on Linux, but I suspect it works their), that is close() function kills cmd process, but on Windows (and Mac) the Java process survives. Inspired by @dasshark response above, I have witted the following helper function that I'm using calling instead of bmp_daemon.stop(). import psutil, signal
from contextlib import suppress
def closeBmpDaemon(bmp_daemon):
if bmp_daemon is not None and bmp_daemon.process is not None:
childs_process = None
try:
cmd_process = psutil.Process(bmp_daemon.process.pid)
childs_process = cmd_process.children(recursive=True)
childs_process = [*childs_process, cmd_process]
bmp_daemon.stop()
finally:
for child in childs_process:
# we can't accidentally kill newly created process
# we can kill only the process we have cached earlier
# if process was already finished we will get NoSuchProcess
# that we're just suppressing
with suppress(psutil.NoSuchProcess):
child.send_signal(signal.SIGTERM) EDIT I have added some comments and make some minor changes. |
I have extracted this function (and more!) above into separate package. |
For Ubuntu 16.04, my personal solution:
|
@KB00100100 hopefully my code is cross-platform. In about 2 month I'm going to test my code on Ubuntu. If my code will fail, I will try to use your code snippet. Thanks for sharing. |
When the server is started it does so using subprocess.Popen('browsermob-proxy.bat')
The result process's pid on windows is the cmd.exe process that controls the bat file, but I don't think Windows is linking the java.exe which the bat file spawns.
Calling server.stop() kills the cmd.exe, but a java.exe is left hanging around at about 35MB.
This may be a problem with windows not killing child process correctly and it is apparently not possible to get the java pid in the bat file without some actual windows-style grep for java.exe.
The text was updated successfully, but these errors were encountered: