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