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

Method _wait_for_data

Lib/asyncio/streams.py:513–539  ·  view source on GitHub ↗

Wait until feed_data() or feed_eof() is called. If stream was paused, automatically resume it.

(self, func_name)

Source from the content-addressed store, hash-verified

511 self._paused = True
512
513 async def _wait_for_data(self, func_name):
514 """Wait until feed_data() or feed_eof() is called.
515
516 If stream was paused, automatically resume it.
517 """
518 # StreamReader uses a future to link the protocol feed_data() method
519 # to a read coroutine. Running two read coroutines at the same time
520 # would have an unexpected behaviour. It would not possible to know
521 # which coroutine would get the next data.
522 if self._waiter is not None:
523 raise RuntimeError(
524 f'{func_name}() called while another coroutine is '
525 f'already waiting for incoming data')
526
527 assert not self._eof, '_wait_for_data after EOF'
528
529 # Waiting for data while paused will make deadlock, so prevent it.
530 # This is essential for readexactly(n) for case when n > self._limit.
531 if self._paused:
532 self._paused = False
533 self._transport.resume_reading()
534
535 self._waiter = self._loop.create_future()
536 try:
537 await self._waiter
538 finally:
539 self._waiter = None
540
541 async def readline(self):
542 """Read chunk of data from the stream until newline (b'\n') is found.

Callers 4

readuntilMethod · 0.95
readMethod · 0.95
readexactlyMethod · 0.95
server_handlerMethod · 0.80

Calls 2

resume_readingMethod · 0.45
create_futureMethod · 0.45

Tested by 1

server_handlerMethod · 0.64