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