skipcheck

TM1 client · Docs · Sessions and logins

Tm1SessionPool

from skipcheck_tm1 import Tm1SessionPool

Sessions on one TM1 server, one per Tm1Identity, for applications that act on behalf of many users. In TM1 identity is the session, so the number of sessions grows with the number of users; the pool keeps that bounded.

# One pool for the application, built once
pool = (
    Tm1SessionPool.builder(Tm1Session.builder().base_url("http://tm1:8010/api/v1/").basic_auth("service", secret))
    .idle_timeout(timedelta(minutes=10))
    .build()
)
# Each time it's needed: the user's session, which logs in on its first request
session = pool.session(Tm1Identity.impersonating(user))
return CubeService(session).list()

  • Get a session for each piece of work and don't keep it: the pool may evict it. Getting one never blocks and sends nothing; the session logs in on its first request.
  • Eviction happens when a session has been idle for idle_timeout, is older than max_age, or the pool is over max_size (least recently used first). It's checked on each session call and every sweep_interval. A session with a request running isn't idle, however long ago it was asked for.
  • An evicted session is closed after close_grace, or when the requests running on it have finished, if that's later: closing it would end them on TM1. The next request for that identity gets a new session.
  • close closes every session at once, and the pool refuses new ones.
  • Nothing falls back: a refused identity fails, and the pool never uses another identity in its place.

Thread-safe. stats reports what the pool holds and has done, for metrics; each eviction is also a tm1.session.pool.evict observation, tagged with its reason.

Members

Stats static
__init__ constructor
builder staticA builder for a pool of sessions with these settings; each identity's session is built from a copy of them.
sessionThe session for identity (the service account if none).
evict_expiredEvicts every session that has been idle too long or is too old, and closes the evicted ones whose grace period is over and that have no request running.
sweep_foreverEvicts expired sessions every sweep_interval until the pool is closed (run it alongside, as a task or a thread); a failure is logged and the sweep goes on.
statsWhat the pool holds and has done so far, for metrics.
is_closed propertyWhether close has been called.
closeCloses every session, including evicted ones still in their grace period, and refuses new ones.
sweep_interval

Stats

static
Stats

__init__

constructor
__init__(builder: Tm1SessionPoolBuilder)

builder

static
builder(sessions: Tm1SessionBuilder) -> Tm1SessionPoolBuilder

A builder for a pool of sessions with these settings; each identity's session is built from a copy of them.

session

session(identity: Tm1Identity | None = None) -> Tm1Session

The session for identity (the service account if none): the pool's, or a new one if it has none, or the one it had has expired. Sends nothing.

evict_expired

evict_expired() -> None

Evicts every session that has been idle too long or is too old, and closes the evicted ones whose grace period is over and that have no request running.

sweep_forever

sweep_forever() -> None

Evicts expired sessions every sweep_interval until the pool is closed (run it alongside, as a task or a thread); a failure is logged and the sweep goes on.

stats

stats() -> Tm1PoolStats

What the pool holds and has done so far, for metrics.

is_closed

property
is_closed: bool

Whether close has been called.

close

close() -> None

Closes every session, including evicted ones still in their grace period, and refuses new ones.

sweep_interval

sweep_interval