Skip to content

[py] fix shutdown and process termination - #3263

Merged
lukeis merged 2 commits into
SeleniumHQ:masterfrom
cgoldberg:process-stoppage
Jan 9, 2017
Merged

[py] fix shutdown and process termination#3263
lukeis merged 2 commits into
SeleniumHQ:masterfrom
cgoldberg:process-stoppage

Conversation

@cgoldberg

@cgoldberg cgoldberg commented Dec 18, 2016

Copy link
Copy Markdown
Member

This PR addresses 2 issues with how webdriver stops services from the python bindings.

  1. Changes the order of events to stop a process. Previously. the order was terminate()->kill()->wait(). So... it would send a SIGTERM signal to the process, immediately followed by a SIGKILL signal. Since wait() is called after the process has already been forcefully stopped, there is nothing to wait on, so it does nothing. The proper sequence should be: terminate()->wait()->kill(). That will send a SIGINT, wait for graceful process termination, then send a SIGKILL to forcefully stop it as a last resort.

  2. Removes the __del__() method from the Service() class. The existence of this method is causing _cookie_temp_file being closed and removed twice #3216. Using __del__() to call stop() is unreliable and not a good idea in Python.
    The proper way to stop the service is to explicitly call the stop() method

  3. Add a try/except inside __del__() so inconsequential exceptions arent displayed


@cgoldberg

Copy link
Copy Markdown
Member Author

/cc @AutomatedTester

def __del__(self):
# subprocess.Popen doesn't send signal on __del__;
# we have to try to stop the launched process.
self.stop()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a try / except around this to make it more stable?

I like the idea of any mistakenly un-quit drivers closing down after the process is quit (the java server does this... also i forget to do driver.quit often when i use the command line repl :) )

@cgoldberg cgoldberg Jan 9, 2017

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, i think that just swallowing exceptions from a try/except is ok here.

I've updated my branch and re-added the del

p.s. I'll get that dastardly __del__ out of there eventually.... fear not! :)

p.p.s. sorry I also piggybacked the tiny style change to the connection test in send_remote_shutdown_command... it was so egregiously un-pythonic. :)

@lukeis lukeis added the C-py Python Bindings label Jan 8, 2017
@lukeis
lukeis merged commit 1e07a85 into SeleniumHQ:master Jan 9, 2017
@cgoldberg

Copy link
Copy Markdown
Member Author

oops.. this should be:
for x in range(30) !!!!!

@cgoldberg

Copy link
Copy Markdown
Member Author

@lukeis can you fix?

@lukeis

lukeis commented Jan 9, 2017

Copy link
Copy Markdown
Member

and this is why i tried to stay away from python :-D

@lukeis

lukeis commented Jan 9, 2017

Copy link
Copy Markdown
Member

3064a0e

@cgoldberg

cgoldberg commented Jan 9, 2017

Copy link
Copy Markdown
Member Author

arg.. im all over the place :(

it should be: for _ in range(30) I forgot range in the original

@lukeis

lukeis commented Jan 9, 2017

Copy link
Copy Markdown
Member

fa53697

@michaelfward michaelfward left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for finding this. I've been looking for months. Great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-py Python Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants