@@ -1226,13 +1226,15 @@ def is_active(self):
1226
1226
1227
1227
def close (self ):
1228
1228
self ._callbacks .clear ()
1229
- if self ._saved_sighandler is not None :
1230
- handler = signal .getsignal (signal .SIGCHLD )
1231
- if handler != self ._sig_chld :
1232
- logger .warning ("SIGCHLD handler was changed by outside code" )
1233
- else :
1234
- signal .signal (signal .SIGCHLD , self ._saved_sighandler )
1235
- self ._saved_sighandler = None
1229
+ if self ._saved_sighandler is None :
1230
+ return
1231
+
1232
+ handler = signal .getsignal (signal .SIGCHLD )
1233
+ if handler != self ._sig_chld :
1234
+ logger .warning ("SIGCHLD handler was changed by outside code" )
1235
+ else :
1236
+ signal .signal (signal .SIGCHLD , self ._saved_sighandler )
1237
+ self ._saved_sighandler = None
1236
1238
1237
1239
def __enter__ (self ):
1238
1240
return self
@@ -1259,15 +1261,17 @@ def attach_loop(self, loop):
1259
1261
# The reason to do it here is that attach_loop() is called from
1260
1262
# unix policy only for the main thread.
1261
1263
# Main thread is required for subscription on SIGCHLD signal
1264
+ if self ._saved_sighandler is not None :
1265
+ return
1266
+
1267
+ self ._saved_sighandler = signal .signal (signal .SIGCHLD , self ._sig_chld )
1262
1268
if self ._saved_sighandler is None :
1263
- self ._saved_sighandler = signal .signal (signal .SIGCHLD , self ._sig_chld )
1264
- if self ._saved_sighandler is None :
1265
- logger .warning ("Previous SIGCHLD handler was set by non-Python code, "
1266
- "restore to default handler on watcher close." )
1267
- self ._saved_sighandler = signal .SIG_DFL
1269
+ logger .warning ("Previous SIGCHLD handler was set by non-Python code, "
1270
+ "restore to default handler on watcher close." )
1271
+ self ._saved_sighandler = signal .SIG_DFL
1268
1272
1269
- # Set SA_RESTART to limit EINTR occurrences.
1270
- signal .siginterrupt (signal .SIGCHLD , False )
1273
+ # Set SA_RESTART to limit EINTR occurrences.
1274
+ signal .siginterrupt (signal .SIGCHLD , False )
1271
1275
1272
1276
def _do_waitpid_all (self ):
1273
1277
for pid in list (self ._callbacks ):
0 commit comments