Table of Contents

Class PipeConnection

Namespace
Gym.Vector
Assembly
Gym.dll

One handle on one end of a two-way pipe (DR-38), the counterpart of Python's multiprocessing.connection.Connection: what AsyncVectorEnv<TObs, TAct> and a custom AsyncVectorWorker talk through. Send(object?) queues a value for the other end, Recv() takes the next value the other end sent, waiting for it, Poll(double?) waits for one without taking it.

public sealed class PipeConnection : IDisposable
Inheritance
PipeConnection
Implements
Inherited Members
Extension Methods

Remarks

Values are passed by reference, not pickled: the receiver gets the sender's object, so a sender must not change what it sent (an array, an info) until the other side is done with it, which Python's copy-on-send never needed.

An end stays open while any handle on it is open, as an OS pipe stays open while any process holds it: a worker thread gets handles of its own (a process inherits its own), so a worker that closes its handle on the parent's end, as Gymnasium's worker does first thing, leaves the parent's handle working. Data already sent stays readable after its sender's end closes; then Recv() reports the end of the stream with EndOfStreamException, Python's EOFError.

Thread-safe: any thread may send, receive or close.

Reference: Lib/multiprocessing/connection.py (CPython 3.12).

Properties

Closed

Whether this handle was closed (closed); the end it is on may still be open through other handles.

public bool Closed { get; }

Property Value

bool

Methods

Close()

close(): closes this handle; once every handle on its end is closed, the other end's receives report the end of the stream after the values already queued. Idempotent.

public void Close()

Dispose()

Closes this handle, as Close().

public void Dispose()

Pipe()

multiprocessing.Pipe(): a new two-way pipe, one handle on each end; what one end sends, the other receives, in order.

public static (PipeConnection First, PipeConnection Second) Pipe()

Returns

(PipeConnection First, PipeConnection Second)

The two ends' handles, as Python's (conn1, conn2).

Poll(double?)

poll(timeout): whether a Recv() would return at once, waiting up to timeout seconds for that; an end of stream counts, as it does in Python.

public bool Poll(double? timeout = 0)

Parameters

timeout double?

Seconds to wait: 0 (the default) does not wait, null waits as long as it takes.

Returns

bool

true when a value is queued or the other end is closed.

Exceptions

OSError

Thrown when this handle is closed.

Recv()

recv(): takes the next value the other end sent, waiting until one arrives.

public object? Recv()

Returns

object

The value.

Exceptions

OSError

Thrown when this handle is closed (handle is closed).

EndOfStreamException

Thrown, as Python's EOFError, when nothing is queued and every handle on the other end is closed: nothing will ever arrive.

Send(object?)

send(obj): queues a value for the other end, after the ones already queued; never waits.

public void Send(object? value)

Parameters

value object

The value, passed by reference.

Exceptions

OSError

Thrown when this handle is closed (handle is closed), or when every handle on the other end is ([Errno 32] Broken pipe), as writing to a pipe nobody reads fails.