# _cpu_affinity

URL: /pounce/api/_cpu_affinity/
Section: api
Description: CPU affinity for worker threads (Linux only).

When enabled, pins each worker to a dedicated CPU core to reduce cache
thrashing and improve throughput on multi-core systems.

---

> For a complete page index, fetch /pounce/llms.txt.

Open LLM text
(/pounce/api/_cpu_affinity/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpounce%2Fapi%2F_cpu_affinity%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpounce%2Fapi%2F_cpu_affinity%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpounce%2Fapi%2F_cpu_affinity%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpounce%2Fapi%2F_cpu_affinity%2Findex.txt)

Module

#
`_cpu_affinity`

CPU affinity for worker threads (Linux only).

When enabled, pins each worker to a dedicated CPU core to reduce cache
thrashing and improve throughput on multi-core systems.

1Function

## Functions

`maybe_pin_worker`

2

`None`

▼

Pin the current thread/process to a CPU core when enabled on Linux.

Called at …

`def maybe_pin_worker(worker_id: int, config: ServerConfig) -> None`

Pin the current thread/process to a CPU core when enabled on Linux.

Called at worker startup. No-op when:

- cpu_affinity is False

- Not running on Linux (os.sched_setaffinity is Linux-only)

- sched_setaffinity raises (e.g. restricted cpuset in containers)

##### Parameters

Name
Type
Description

`worker_id`
`int`

Worker index (0, 1, ...).

`config`
`ServerConfig (/pounce/api/config/#ServerConfig)`

Server configuration (reads cpu_affinity).
