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

Method _interrupted_reads

Lib/test/_test_eintr.py:126–154  ·  view source on GitHub ↗

Make a fd which will force block on read of expected bytes.

(self)

Source from the content-addressed store, hash-verified

124 self._test_wait_single(lambda pid: os.wait4(pid, 0))
125
126 def _interrupted_reads(self):
127 """Make a fd which will force block on read of expected bytes."""
128 rd, wr = os.pipe()
129 self.addCleanup(os.close, rd)
130 # wr closed explicitly by parent
131
132 # the payload below are smaller than PIPE_BUF, hence the writes will be
133 # atomic
134 data = [b"hello", b"world", b"spam"]
135
136 code = '\n'.join((
137 'import os, sys, time',
138 '',
139 'wr = int(sys.argv[1])',
140 f'data = {data!r}',
141 f'sleep_time = {self.sleep_time!r}',
142 '',
143 'for item in data:',
144 ' # let the parent block on read()',
145 ' time.sleep(sleep_time)',
146 ' os.write(wr, item)',
147 ))
148
149 proc = self.subprocess(code, str(wr), pass_fds=[wr])
150 with kill_on_error(proc):
151 os.close(wr)
152 for datum in data:
153 yield rd, datum
154 self.assertEqual(proc.wait(), 0)
155
156 def test_read(self):
157 for fd, expected in self._interrupted_reads():

Callers 2

test_readMethod · 0.95
test_readintoMethod · 0.95

Calls 9

strFunction · 0.85
addCleanupMethod · 0.80
subprocessMethod · 0.80
kill_on_errorFunction · 0.70
pipeMethod · 0.45
joinMethod · 0.45
closeMethod · 0.45
assertEqualMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected