@@ -911,46 +911,29 @@ class PidfdChildWatcher(AbstractChildWatcher):
911
911
recent (5.3+) kernels.
912
912
"""
913
913
914
- def __init__ (self ):
915
- self ._loop = None
916
- self ._callbacks = {}
917
-
918
914
def __enter__ (self ):
919
915
return self
920
916
921
917
def __exit__ (self , exc_type , exc_value , exc_traceback ):
922
918
pass
923
919
924
920
def is_active (self ):
925
- return self . _loop is not None and self . _loop . is_running ()
921
+ return True
926
922
927
923
def close (self ):
928
- self . attach_loop ( None )
924
+ pass
929
925
930
926
def attach_loop (self , loop ):
931
- if self ._loop is not None and loop is None and self ._callbacks :
932
- warnings .warn (
933
- 'A loop is being detached '
934
- 'from a child watcher with pending handlers' ,
935
- RuntimeWarning )
936
- for pidfd , _ , _ in self ._callbacks .values ():
937
- self ._loop ._remove_reader (pidfd )
938
- os .close (pidfd )
939
- self ._callbacks .clear ()
940
- self ._loop = loop
927
+ pass
941
928
942
929
def add_child_handler (self , pid , callback , * args ):
943
- existing = self ._callbacks .get (pid )
944
- if existing is not None :
945
- self ._callbacks [pid ] = existing [0 ], callback , args
946
- else :
947
- pidfd = os .pidfd_open (pid )
948
- self ._loop ._add_reader (pidfd , self ._do_wait , pid )
949
- self ._callbacks [pid ] = pidfd , callback , args
930
+ loop = events .get_running_loop ()
931
+ pidfd = os .pidfd_open (pid )
932
+ loop ._add_reader (pidfd , self ._do_wait , pid , pidfd , callback , args )
950
933
951
- def _do_wait (self , pid ):
952
- pidfd , callback , args = self . _callbacks . pop ( pid )
953
- self . _loop ._remove_reader (pidfd )
934
+ def _do_wait (self , pid , pidfd , callback , args ):
935
+ loop = events . get_running_loop ( )
936
+ loop ._remove_reader (pidfd )
954
937
try :
955
938
_ , status = os .waitpid (pid , 0 )
956
939
except ChildProcessError :
@@ -968,12 +951,9 @@ def _do_wait(self, pid):
968
951
callback (pid , returncode , * args )
969
952
970
953
def remove_child_handler (self , pid ):
971
- try :
972
- pidfd , _ , _ = self ._callbacks .pop (pid )
973
- except KeyError :
974
- return False
975
- self ._loop ._remove_reader (pidfd )
976
- os .close (pidfd )
954
+ # asyncio never calls remove_child_handler() !!!
955
+ # The method is no-op but is implemented because
956
+ # abstract base classes require it.
977
957
return True
978
958
979
959
0 commit comments