Skip to content

Commit 58422be

Browse files
author
James William Pye
committed
Add a shutdown method providing immediate, but clean stop(SIGINT).
start/stop = nice. shutdown = turn things off now. kill = destruction(you get to use ipcrm).
1 parent 32ea55a commit 58422be

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

postgresql/cluster.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,12 @@ def init(self,
201201
+ tuple(opts) \
202202
+ supw_file \
203203
+ extra_args
204+
204205
p = sp.Popen(
205206
cmd,
206207
stdin = sp.PIPE,
207208
stdout = logfile,
208-
stderr = sp.PIPE
209+
stderr = sp.PIPE,
209210
)
210211
p.stdin.close()
211212

@@ -222,7 +223,7 @@ def init(self,
222223
if rc != 0:
223224
r = p.stderr.read().strip()
224225
try:
225-
msg = r.decode('utf-8') # :(
226+
msg = r.decode('utf-8')
226227
except UnicodeDecodeError:
227228
# split up the lines, and use rep.
228229
msg = os.linesep.join([
@@ -243,7 +244,7 @@ def drop(self):
243244
Stop the cluster and remove it from the filesystem
244245
"""
245246
if self.running():
246-
self.stop()
247+
self.shutdown()
247248
try:
248249
self.wait_until_stopped()
249250
except pg_exc.ClusterTimeoutError:
@@ -312,9 +313,7 @@ def restart(self, logfile = None, settings = None, timeout = 10):
312313

313314
def stop(self):
314315
"""
315-
Stop the cluster gracefully(SIGTERM).
316-
317-
Does *not* wait for shutdown.
316+
Stop the cluster gracefully waiting for clients to disconnect(SIGTERM).
318317
"""
319318
pid = self.pid
320319
if pid is not None:
@@ -324,6 +323,18 @@ def stop(self):
324323
if e.errno != errno.ESRCH:
325324
raise
326325

326+
def shutdown(self):
327+
"""
328+
Shutdown the cluster as soon as possible, disconnecting clients.
329+
"""
330+
pid = self.pid
331+
if pid is not None:
332+
try:
333+
os.kill(pid, signal.SIGINT)
334+
except OSError as e:
335+
if e.errno != errno.ESRCH:
336+
raise
337+
327338
def kill(self):
328339
"""
329340
Stop the cluster immediately(SIGKILL).

0 commit comments

Comments
 (0)