MCPcopy Index your code
hub / github.com/python/cpython / _poll

Method _poll

Lib/asyncio/windows_events.py:762–817  ·  view source on GitHub ↗
(self, timeout=None)

Source from the content-addressed store, hash-verified

760 return s
761
762 def _poll(self, timeout=None):
763 if timeout is None:
764 ms = INFINITE
765 elif timeout < 0:
766 raise ValueError("negative timeout")
767 else:
768 # GetQueuedCompletionStatus() has a resolution of 1 millisecond,
769 # round away from zero to wait *at least* timeout seconds.
770 ms = math.ceil(timeout * 1e3)
771 if ms >= INFINITE:
772 raise ValueError("timeout too big")
773
774 while True:
775 status = _overlapped.GetQueuedCompletionStatus(self._iocp, ms)
776 if status is None:
777 break
778 ms = 0
779
780 err, transferred, key, address = status
781 try:
782 f, ov, obj, callback = self._cache.pop(address)
783 except KeyError:
784 if self._loop.get_debug():
785 self._loop.call_exception_handler({
786 'message': ('GetQueuedCompletionStatus() returned an '
787 'unexpected event'),
788 'status': ('err=%s transferred=%s key=%#x address=%#x'
789 % (err, transferred, key, address)),
790 })
791
792 # key is either zero, or it is used to return a pipe
793 # handle which should be closed to avoid a leak.
794 if key not in (0, _overlapped.INVALID_HANDLE_VALUE):
795 _winapi.CloseHandle(key)
796 continue
797
798 if obj in self._stopped_serving:
799 f.cancel()
800 # Don't call the callback if _register() already read the result or
801 # if the overlapped has been cancelled
802 elif not f.done():
803 try:
804 value = callback(transferred, key, ov)
805 except OSError as e:
806 f.set_exception(e)
807 self._results.append(f)
808 else:
809 f.set_result(value)
810 self._results.append(f)
811 finally:
812 f = None
813
814 # Remove unregistered futures
815 for ov in self._unregistered:
816 self._cache.pop(ov.address, None)
817 self._unregistered.clear()
818
819 def _stop_serving(self, obj):

Callers 3

selectMethod · 0.95
closeMethod · 0.95

Calls 10

callbackFunction · 0.70
popMethod · 0.45
get_debugMethod · 0.45
cancelMethod · 0.45
doneMethod · 0.45
set_exceptionMethod · 0.45
appendMethod · 0.45
set_resultMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected