-
Notifications
You must be signed in to change notification settings - Fork 6
use pg-ctl stop to cleanup before killing the process #16
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one last request might be to rebase and squash these two commit together so that there's only one remaining, but that's mostly aesthetic. We'll let @ugtar do the final merge, tho.
e3c64bd
to
f055454
Compare
Just squashed and force pushed! |
@@ -358,6 +359,8 @@ def cleanup(self): | |||
stdout=subprocess.DEVNULL, | |||
) | |||
elif self.pg_process: | |||
pg_stop_cmd = ['pg_ctl', 'stop', '-D', self.pg_data_dir, '-m' 'fast'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to be able to override pg_ctl in the same way that we do postgres or initdb, in the case the user is using an alternative postgres install that is not in the PATH. This needs a default, and an argument (plus said default) in the constructor. See for example DEFAULT_POSTGRES
or DEFAULT_INITDB
@@ -358,6 +359,8 @@ def cleanup(self): | |||
stdout=subprocess.DEVNULL, | |||
) | |||
elif self.pg_process: | |||
pg_stop_cmd = ['pg_ctl', 'stop', '-D', self.pg_data_dir, '-m' 'fast'] | |||
self.run_cmd(pg_stop_cmd, level=2, bg=True).wait() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think since run_cmd with level 2 can potentially produce stdout and stderr, instead of .wait()
we should call .communicate()
. Also, since this command can be caught by the pg process or hang, we should have a timeout at which point we give up and call kill()
anyway. Maybe 10 seconds?
The python docs have an example of how to do this properly, catching the TimeoutExpired
exception https://docs.python.org/3/library/subprocess.html#subprocess.Popen.communicate
thanks @DShau22, sorry I took so long to get to this, I've been swamped at dayjob |
Proposed fix for this issue
Ran
make test
to confirm that all existing tests still pass, andmake check
for formattingDocs on pg-ctl for reference