@@ -1152,13 +1152,15 @@ def is_active(self):
1152
1152
1153
1153
def close (self ):
1154
1154
self ._callbacks .clear ()
1155
- if self ._saved_sighandler is not None :
1156
- handler = signal .getsignal (signal .SIGCHLD )
1157
- if handler != self ._sig_chld :
1158
- logger .warning ("SIGCHLD handler was changed by outside code" )
1159
- else :
1160
- signal .signal (signal .SIGCHLD , self ._saved_sighandler )
1161
- self ._saved_sighandler = None
1155
+ if self ._saved_sighandler is None :
1156
+ return
1157
+
1158
+ handler = signal .getsignal (signal .SIGCHLD )
1159
+ if handler != self ._sig_chld :
1160
+ logger .warning ("SIGCHLD handler was changed by outside code" )
1161
+ else :
1162
+ signal .signal (signal .SIGCHLD , self ._saved_sighandler )
1163
+ self ._saved_sighandler = None
1162
1164
1163
1165
def __enter__ (self ):
1164
1166
return self
@@ -1185,15 +1187,17 @@ def attach_loop(self, loop):
1185
1187
# The reason to do it here is that attach_loop() is called from
1186
1188
# unix policy only for the main thread.
1187
1189
# Main thread is required for subscription on SIGCHLD signal
1190
+ if self ._saved_sighandler is not None :
1191
+ return
1192
+
1193
+ self ._saved_sighandler = signal .signal (signal .SIGCHLD , self ._sig_chld )
1188
1194
if self ._saved_sighandler is None :
1189
- self ._saved_sighandler = signal .signal (signal .SIGCHLD , self ._sig_chld )
1190
- if self ._saved_sighandler is None :
1191
- logger .warning ("Previous SIGCHLD handler was set by non-Python code, "
1192
- "restore to default handler on watcher close." )
1193
- self ._saved_sighandler = signal .SIG_DFL
1195
+ logger .warning ("Previous SIGCHLD handler was set by non-Python code, "
1196
+ "restore to default handler on watcher close." )
1197
+ self ._saved_sighandler = signal .SIG_DFL
1194
1198
1195
- # Set SA_RESTART to limit EINTR occurrences.
1196
- signal .siginterrupt (signal .SIGCHLD , False )
1199
+ # Set SA_RESTART to limit EINTR occurrences.
1200
+ signal .siginterrupt (signal .SIGCHLD , False )
1197
1201
1198
1202
def _do_waitpid_all (self ):
1199
1203
for pid in list (self ._callbacks ):
0 commit comments