Context
Each LiteQueue now owns one write connection and ten read connections. close() releases all eleven and is idempotent, but the class does not support with LiteQueue(...) as queue:.
The recent constructor changes also create the write connection before validating the existing database schema and stored maxsize. If construction raises at that stage, __init__ does not explicitly close the partially created connection.
Why implement this
Eleven connections make explicit cleanup more important. Context-manager support gives callers a standard, reliable ownership pattern. Constructor cleanup prevents file descriptors and database handles from depending on garbage collection after expected validation errors.
Proposed direction
- Add
__enter__() that returns self.
- Add
__exit__() that closes all owned connections and returns False so active exceptions propagate.
- Preserve idempotent
close() behavior.
- Wrap constructor setup so any failure closes every connection created so far.
- Document that LiteQueue owns all of its SQLite connections.
Acceptance criteria
Context
Each
LiteQueuenow owns one write connection and ten read connections.close()releases all eleven and is idempotent, but the class does not supportwith LiteQueue(...) as queue:.The recent constructor changes also create the write connection before validating the existing database schema and stored
maxsize. If construction raises at that stage,__init__does not explicitly close the partially created connection.Why implement this
Eleven connections make explicit cleanup more important. Context-manager support gives callers a standard, reliable ownership pattern. Constructor cleanup prevents file descriptors and database handles from depending on garbage collection after expected validation errors.
Proposed direction
__enter__()that returnsself.__exit__()that closes all owned connections and returnsFalseso active exceptions propagate.close()behavior.Acceptance criteria
with LiteQueue(...) as queue:closes the write connection and full read pool.close()remains safe.make testpasses.