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

Method write

Lib/asyncio/unix_events.py:704–737  ·  view source on GitHub ↗
(self, data)

Source from the content-addressed store, hash-verified

702 self._close()
703
704 def write(self, data):
705 assert isinstance(data, (bytes, bytearray, memoryview)), repr(data)
706 if isinstance(data, bytearray):
707 data = memoryview(data)
708 if not data:
709 return
710
711 if self._conn_lost or self._closing:
712 if self._conn_lost >= constants.LOG_THRESHOLD_FOR_CONNLOST_WRITES:
713 logger.warning('pipe closed by peer or '
714 'os.write(pipe, data) raised exception.')
715 self._conn_lost += 1
716 return
717
718 if not self._buffer:
719 # Attempt to send it right away first.
720 try:
721 n = os.write(self._fileno, data)
722 except (BlockingIOError, InterruptedError):
723 n = 0
724 except (SystemExit, KeyboardInterrupt):
725 raise
726 except BaseException as exc:
727 self._conn_lost += 1
728 self._fatal_error(exc, 'Fatal write error on pipe transport')
729 return
730 if n == len(data):
731 return
732 elif n > 0:
733 data = memoryview(data)[n:]
734 self._loop._add_writer(self._fileno, self._write_ready)
735
736 self._buffer += data
737 self._maybe_pause_protocol()
738
739 def _write_ready(self):
740 assert self._buffer, 'Data should not be empty'

Callers 1

_write_readyMethod · 0.45

Calls 4

_fatal_errorMethod · 0.95
_maybe_pause_protocolMethod · 0.80
warningMethod · 0.45
_add_writerMethod · 0.45

Tested by

no test coverage detected