(
self,
close: bool,
pause: bool = True,
service_id: Optional[ObjectId] = None,
interrupt_connections: bool = False,
)
| 805 | return self.state == PoolState.CLOSED |
| 806 | |
| 807 | async def _reset( |
| 808 | self, |
| 809 | close: bool, |
| 810 | pause: bool = True, |
| 811 | service_id: Optional[ObjectId] = None, |
| 812 | interrupt_connections: bool = False, |
| 813 | ) -> None: |
| 814 | old_state = self.state |
| 815 | async with self.size_cond: |
| 816 | if self.closed: |
| 817 | return |
| 818 | if self.opts.pause_enabled and pause and not self.opts.load_balanced: |
| 819 | old_state, self.state = self.state, PoolState.PAUSED |
| 820 | self.gen.inc(service_id) |
| 821 | newpid = os.getpid() |
| 822 | if self.pid != newpid: |
| 823 | self.pid = newpid |
| 824 | self.active_sockets = 0 |
| 825 | self.operation_count = 0 |
| 826 | if service_id is None: |
| 827 | sockets, self.conns = self.conns, collections.deque() |
| 828 | else: |
| 829 | discard: collections.deque = collections.deque() # type: ignore[type-arg] |
| 830 | keep: collections.deque = collections.deque() # type: ignore[type-arg] |
| 831 | for conn in self.conns: |
| 832 | if conn.service_id == service_id: |
| 833 | discard.append(conn) |
| 834 | else: |
| 835 | keep.append(conn) |
| 836 | sockets = discard |
| 837 | self.conns = keep |
| 838 | |
| 839 | if close: |
| 840 | self.state = PoolState.CLOSED |
| 841 | # Clear the wait queue |
| 842 | self._max_connecting_cond.notify_all() |
| 843 | self.size_cond.notify_all() |
| 844 | |
| 845 | if interrupt_connections: |
| 846 | for context in self.active_contexts: |
| 847 | context.cancel() |
| 848 | |
| 849 | listeners = self.opts._event_listeners |
| 850 | # CMAP spec says that close() MUST close sockets before publishing the |
| 851 | # PoolClosedEvent but that reset() SHOULD close sockets *after* |
| 852 | # publishing the PoolClearedEvent. |
| 853 | if close: |
| 854 | if not _IS_SYNC: |
| 855 | await asyncio.gather( |
| 856 | *[conn.close_conn(ConnectionClosedReason.POOL_CLOSED) for conn in sockets], # type: ignore[func-returns-value] |
| 857 | return_exceptions=True, |
| 858 | ) |
| 859 | else: |
| 860 | for conn in sockets: |
| 861 | await conn.close_conn(ConnectionClosedReason.POOL_CLOSED) |
| 862 | if self.enabled_for_cmap: |
| 863 | assert listeners is not None |
| 864 | listeners.publish_pool_closed(self.address) |
no test coverage detected