# session.Session.lock

- **Module:** session.Session
- **Package:** libtmux
- **Language:** Rust
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-rs/blob/8a648c0894dfffc9303583f753b6c8ae01f2fe76/crates/libtmux/src/session.rs#L722
- **Page:** https://libtmux.org/reference/rs/session-session-lock/

```
session.Session.lock(self) -> Result<(), Error>
```

Lock every client attached to this session.

tmux runs the `lock-command` to lock, so what a locked client shows is
that command's business rather than this one's.

# Errors

Returns an error when tmux cannot be reached or refuses the lock.

## Example

```rust
let guard = libtmux::test::TestServer::new().await?;
let session = guard.server().new_session("locked").await?;

// Locking a session nobody is attached to is accepted and does nothing.
session.lock().await?;

guard.shutdown().await?;
```
