MCPcopy Index your code
hub / github.com/RustPython/RustPython / PipeConnection

Class PipeConnection

Lib/multiprocessing/connection.py:268–361  ·  view source on GitHub ↗

Connection class based on a Windows named pipe. Overlapped I/O is used, so the handles must have been created with FILE_FLAG_OVERLAPPED.

Source from the content-addressed store, hash-verified

266if _winapi:
267
268 class PipeConnection(_ConnectionBase):
269 """
270 Connection class based on a Windows named pipe.
271 Overlapped I/O is used, so the handles must have been created
272 with FILE_FLAG_OVERLAPPED.
273 """
274 _got_empty_message = False
275 _send_ov = None
276
277 def _close(self, _CloseHandle=_winapi.CloseHandle):
278 ov = self._send_ov
279 if ov is not None:
280 # Interrupt WaitForMultipleObjects() in _send_bytes()
281 ov.cancel()
282 _CloseHandle(self._handle)
283
284 def _send_bytes(self, buf):
285 if self._send_ov is not None:
286 # A connection should only be used by a single thread
287 raise ValueError("concurrent send_bytes() calls "
288 "are not supported")
289 ov, err = _winapi.WriteFile(self._handle, buf, overlapped=True)
290 self._send_ov = ov
291 try:
292 if err == _winapi.ERROR_IO_PENDING:
293 waitres = _winapi.WaitForMultipleObjects(
294 [ov.event], False, INFINITE)
295 assert waitres == WAIT_OBJECT_0
296 except:
297 ov.cancel()
298 raise
299 finally:
300 self._send_ov = None
301 nwritten, err = ov.GetOverlappedResult(True)
302 if err == _winapi.ERROR_OPERATION_ABORTED:
303 # close() was called by another thread while
304 # WaitForMultipleObjects() was waiting for the overlapped
305 # operation.
306 raise OSError(errno.EPIPE, "handle is closed")
307 assert err == 0
308 assert nwritten == len(buf)
309
310 def _recv_bytes(self, maxsize=None):
311 if self._got_empty_message:
312 self._got_empty_message = False
313 return io.BytesIO()
314 else:
315 bsize = 128 if maxsize is None else min(maxsize, 128)
316 try:
317 ov, err = _winapi.ReadFile(self._handle, bsize,
318 overlapped=True)
319 try:
320 if err == _winapi.ERROR_IO_PENDING:
321 waitres = _winapi.WaitForMultipleObjects(
322 [ov.event], False, INFINITE)
323 assert waitres == WAIT_OBJECT_0
324 except:
325 ov.cancel()

Callers 4

PipeFunction · 0.85
acceptMethod · 0.85
PipeClientFunction · 0.85
rebuild_pipe_connectionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected