Skip to main content

Practice · 2 of 2

A pool that knows its size

CHALLENGE
Difficulty: advanced+25 XP

Implement ConnectionPool(size) with PoolExhausted: - starts with size idle connections ('conn-0' … 'conn-(size-1)') - checkout() returns an idle connection, or raises PoolExhausted('pool exhausted') when none remain — capacity is never exceeded - checkin(conn, dirty=False) returns the connection to the idle set; if dirty is True the returned name gets ':clean' appended (simulating a ROLLBACK before reuse) — the returned name is what the next checkout hands out - in_use property: how many connections are currently lent The rule under test: a pool of N can never lend more than N.

Back to lesson: Practice: Transaction & Pool Drills