summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-12-16 18:11:51 (GMT)
committerGitHub <noreply@github.com>2020-12-16 18:11:51 (GMT)
commitdd262ef46d2e2fff4c413cfa5faa9e72cd36220e (patch)
treee941f501a8b7bad6e8a626d2858a1d49669f1914 /Lib
parentd549d0b5575b390431b7b26999151f79f74d4516 (diff)
downloadcpython-dd262ef46d2e2fff4c413cfa5faa9e72cd36220e.zip
cpython-dd262ef46d2e2fff4c413cfa5faa9e72cd36220e.tar.gz
cpython-dd262ef46d2e2fff4c413cfa5faa9e72cd36220e.tar.bz2
bpo-38323: Add guard clauses in MultiLoopChildWatcher. (GH-22756)
This is a trivial refactor in preparation for a fix for bpo-38323. (cherry picked from commit 66d3b589c44fcbcf9afe1e442d9beac3bd8bcd34) Co-authored-by: Chris Jerdonek <chris.jerdonek@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/asyncio/unix_events.py32
1 files changed, 18 insertions, 14 deletions
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index 1ff8c42..0420529 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -1152,13 +1152,15 @@ class MultiLoopChildWatcher(AbstractChildWatcher):
def close(self):
self._callbacks.clear()
- if self._saved_sighandler is not None:
- handler = signal.getsignal(signal.SIGCHLD)
- if handler != self._sig_chld:
- logger.warning("SIGCHLD handler was changed by outside code")
- else:
- signal.signal(signal.SIGCHLD, self._saved_sighandler)
- self._saved_sighandler = None
+ if self._saved_sighandler is None:
+ return
+
+ handler = signal.getsignal(signal.SIGCHLD)
+ if handler != self._sig_chld:
+ logger.warning("SIGCHLD handler was changed by outside code")
+ else:
+ signal.signal(signal.SIGCHLD, self._saved_sighandler)
+ self._saved_sighandler = None
def __enter__(self):
return self
@@ -1185,15 +1187,17 @@ class MultiLoopChildWatcher(AbstractChildWatcher):
# The reason to do it here is that attach_loop() is called from
# unix policy only for the main thread.
# Main thread is required for subscription on SIGCHLD signal
+ if self._saved_sighandler is not None:
+ return
+
+ self._saved_sighandler = signal.signal(signal.SIGCHLD, self._sig_chld)
if self._saved_sighandler is None:
- self._saved_sighandler = signal.signal(signal.SIGCHLD, self._sig_chld)
- if self._saved_sighandler is None:
- logger.warning("Previous SIGCHLD handler was set by non-Python code, "
- "restore to default handler on watcher close.")
- self._saved_sighandler = signal.SIG_DFL
+ logger.warning("Previous SIGCHLD handler was set by non-Python code, "
+ "restore to default handler on watcher close.")
+ self._saved_sighandler = signal.SIG_DFL
- # Set SA_RESTART to limit EINTR occurrences.
- signal.siginterrupt(signal.SIGCHLD, False)
+ # Set SA_RESTART to limit EINTR occurrences.
+ signal.siginterrupt(signal.SIGCHLD, False)
def _do_waitpid_all(self):
for pid in list(self._callbacks):