MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / _PoolGeneration

Class _PoolGeneration

pymongo/synchronous/pool.py:660–688  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

658
659
660class _PoolGeneration:
661 def __init__(self) -> None:
662 # Maps service_id to generation.
663 self._generations: dict[ObjectId, int] = collections.defaultdict(int)
664 # Overall pool generation.
665 self._generation = 0
666
667 def get(self, service_id: Optional[ObjectId]) -> int:
668 """Get the generation for the given service_id."""
669 if service_id is None:
670 return self._generation
671 return self._generations[service_id]
672
673 def get_overall(self) -> int:
674 """Get the Pool's overall generation."""
675 return self._generation
676
677 def inc(self, service_id: Optional[ObjectId]) -> None:
678 """Increment the generation for the given service_id."""
679 self._generation += 1
680 if service_id is None:
681 for service_id in self._generations:
682 self._generations[service_id] += 1
683 else:
684 self._generations[service_id] += 1
685
686 def stale(self, gen: int, service_id: Optional[ObjectId]) -> bool:
687 """Return if the given generation for a given service_id is stale."""
688 return gen != self.get(service_id)
689
690
691class PoolState:

Callers 3

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected