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 66d3b589c4)

Co-authored-by: Chris Jerdonek <chris.jerdonek@gmail.com>
This commit is contained in:
Miss Islington (bot) 2020-12-16 10:10:37 -08:00 committed by GitHub
parent 9d409d6b47
commit bf0eed3e60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1230,7 +1230,9 @@ class MultiLoopChildWatcher(AbstractChildWatcher):
def close(self):
self._callbacks.clear()
if self._saved_sighandler is not 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")
@ -1263,7 +1265,9 @@ 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 None:
if self._saved_sighandler is not None:
return
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, "