# TransportBase

## class TransportBase[source]

Bases: [`ABC`](https://docs.python.org/3/library/abc.html#abc.ABC "(in Python v3.15)")

The contract a transport implements: `_open_session`, `_teardown_session`, `is_open`, plus shared ownership.

Ownership is deferred-teardown: opened by the first owner, torn down by the last. Holders are
the objects that own the connection, so a device serving several categories holds the transport
once on its own behalf and does its own device-level teardown before releasing.

Initialize holder tracking and the reentrant lock.

Attributes

| [`is_open`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.transport_base.TransportBase.md#instro.lib.transports.transport_base.TransportBase.is_open "instro.lib.transports.transport_base.TransportBase.is_open") | Whether the underlying connection is currently open. |
| --- | --- |

Methods

| [`close`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.transport_base.TransportBase.md#instro.lib.transports.transport_base.TransportBase.close "instro.lib.transports.transport_base.TransportBase.close") | Close and teardown; with a holder, remove it and tear down only when the last owner leaves. |
| --- | --- |
| [`lock`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.transport_base.TransportBase.md#instro.lib.transports.transport_base.TransportBase.lock "instro.lib.transports.transport_base.TransportBase.lock") | Return the reentrant resource lock for atomic multi-step sequences; the holder may write/query/read inside it. |
| [`open`](https://dev.nominal.io/instro/ref/library/instro.lib.transports.transport_base.TransportBase.md#instro.lib.transports.transport_base.TransportBase.open "instro.lib.transports.transport_base.TransportBase.open") | Open the connection (idempotent); with a holder, admit it and return True only for the first owner. |

### open(holder: object | None = None) → bool[source]

Open the connection (idempotent); with a holder, admit it and return True only for the first owner.

### close(holder: object | None = None) → None[source]

Close and teardown; with a holder, remove it and tear down only when the last owner leaves.

A holder that needs to talk to the instrument before the connection goes (releasing a remote
lock, say) does that in its own `close` before calling this, while the session is still up.

Raises `UnknownHolderError` when an unrecognized holder closes while others still own the
connection, because that is the case where ignoring it silently strands the real owners and
leaves the connection open forever. Once the last owner has left there is nothing to strand,
so a repeat close is a no-op and close stays idempotent.

### lock() → RLock[source]

Return the reentrant resource lock for atomic multi-step sequences; the holder may write/query/read inside it.

### abstract property is_open: bool

Whether the underlying connection is currently open.
