From 6ab258b49ac9c21acf9c212d561879fde648cfc6 Mon Sep 17 00:00:00 2001 From: Scott Stevenson Date: Mon, 13 Nov 2017 18:24:27 +0000 Subject: [PATCH] Reduce duplication in PtyWithClients.terminate --- terminado/management.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/terminado/management.py b/terminado/management.py index 15b236f..3c7dd66 100644 --- a/terminado/management.py +++ b/terminado/management.py @@ -70,22 +70,12 @@ def terminate(self, force=False): if not self.ptyproc.isalive(): raise gen.Return(True) try: - self.kill(signal.SIGHUP) - yield sleep() - if not self.ptyproc.isalive(): - raise gen.Return(True) - self.kill(signal.SIGCONT) - yield sleep() - if not self.ptyproc.isalive(): - raise gen.Return(True) - self.kill(signal.SIGINT) - yield sleep() - if not self.ptyproc.isalive(): - raise gen.Return(True) - self.kill(signal.SIGTERM) - yield sleep() - if not self.ptyproc.isalive(): - raise gen.Return(True) + for sig in [signal.SIGHUP, signal.SIGCONT, signal.SIGINT, + signal.SIGTERM]: + self.kill(sig) + yield sleep() + if not self.ptyproc.isalive(): + raise gen.Return(True) if force: self.kill(signal.SIGKILL) yield sleep()