MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / wait

Function wait

tools/python-3.11.9-amd64/Lib/multiprocessing/connection.py:844–920  ·  view source on GitHub ↗

Wait till an object in object_list is ready/readable. Returns list of those objects in object_list which are ready/readable.

(object_list, timeout=None)

Source from the content-addressed store, hash-verified

842 _ready_errors = {_winapi.ERROR_BROKEN_PIPE, _winapi.ERROR_NETNAME_DELETED}
843
844 def wait(object_list, timeout=None):
845 '''
846 Wait till an object in object_list is ready/readable.
847
848 Returns list of those objects in object_list which are ready/readable.
849 '''
850 if timeout is None:
851 timeout = INFINITE
852 elif timeout < 0:
853 timeout = 0
854 else:
855 timeout = int(timeout * 1000 + 0.5)
856
857 object_list = list(object_list)
858 waithandle_to_obj = {}
859 ov_list = []
860 ready_objects = set()
861 ready_handles = set()
862
863 try:
864 for o in object_list:
865 try:
866 fileno = getattr(o, 'fileno')
867 except AttributeError:
868 waithandle_to_obj[o.__index__()] = o
869 else:
870 # start an overlapped read of length zero
871 try:
872 ov, err = _winapi.ReadFile(fileno(), 0, True)
873 except OSError as e:
874 ov, err = None, e.winerror
875 if err not in _ready_errors:
876 raise
877 if err == _winapi.ERROR_IO_PENDING:
878 ov_list.append(ov)
879 waithandle_to_obj[ov.event] = o
880 else:
881 # If o.fileno() is an overlapped pipe handle and
882 # err == 0 then there is a zero length message
883 # in the pipe, but it HAS NOT been consumed...
884 if ov and sys.getwindowsversion()[:2] >= (6, 2):
885 # ... except on Windows 8 and later, where
886 # the message HAS been consumed.
887 try:
888 _, err = ov.GetOverlappedResult(False)
889 except OSError as e:
890 err = e.winerror
891 if not err and hasattr(o, '_got_empty_message'):
892 o._got_empty_message = True
893 ready_objects.add(o)
894 timeout = 0
895
896 ready_handles = _exhaustive_wait(waithandle_to_obj.keys(), timeout)
897 finally:
898 # request that overlapped reads stop
899 for ov in ov_list:
900 ov.cancel()
901

Callers 7

waitMethod · 0.90
pollMethod · 0.90
is_aliveMethod · 0.90
joinMethod · 0.90
_pollMethod · 0.70
_pollMethod · 0.70
_wait_for_updatesMethod · 0.70

Calls 12

listFunction · 0.85
filenoFunction · 0.85
_exhaustive_waitFunction · 0.85
setFunction · 0.50
__index__Method · 0.45
appendMethod · 0.45
addMethod · 0.45
keysMethod · 0.45
cancelMethod · 0.45
updateMethod · 0.45
registerMethod · 0.45
selectMethod · 0.45

Tested by

no test coverage detected