Skip to main content

Practice ยท 2 of 2

A pool that knows its size

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.

Difficulty: advanced

Back to lesson: Practice: Transaction & Pool Drills