|
53 | 53 | from pymongo.change_stream import ClusterChangeStream
|
54 | 54 | from pymongo.client_options import ClientOptions
|
55 | 55 | from pymongo.command_cursor import CommandCursor
|
56 |
| -from pymongo.cursor_manager import CursorManager |
57 | 56 | from pymongo.errors import (AutoReconnect,
|
58 | 57 | BulkWriteError,
|
59 | 58 | ConfigurationError,
|
@@ -704,7 +703,6 @@ def __init__(
|
704 | 703 |
|
705 | 704 | self.__default_database_name = dbase
|
706 | 705 | self.__lock = threading.Lock()
|
707 |
| - self.__cursor_manager = None |
708 | 706 | self.__kill_cursors_queue = []
|
709 | 707 |
|
710 | 708 | self._event_listeners = options.pool_options.event_listeners
|
@@ -1209,35 +1207,6 @@ def close(self):
|
1209 | 1207 | # TODO: PYTHON-1921 Encrypted MongoClients cannot be re-opened.
|
1210 | 1208 | self._encrypter.close()
|
1211 | 1209 |
|
1212 |
| - def set_cursor_manager(self, manager_class): |
1213 |
| - """DEPRECATED - Set this client's cursor manager. |
1214 |
| -
|
1215 |
| - Raises :class:`TypeError` if `manager_class` is not a subclass of |
1216 |
| - :class:`~pymongo.cursor_manager.CursorManager`. A cursor manager |
1217 |
| - handles closing cursors. Different managers can implement different |
1218 |
| - policies in terms of when to actually kill a cursor that has |
1219 |
| - been closed. |
1220 |
| -
|
1221 |
| - :Parameters: |
1222 |
| - - `manager_class`: cursor manager to use |
1223 |
| -
|
1224 |
| - .. versionchanged:: 3.3 |
1225 |
| - Deprecated, for real this time. |
1226 |
| -
|
1227 |
| - .. versionchanged:: 3.0 |
1228 |
| - Undeprecated. |
1229 |
| - """ |
1230 |
| - warnings.warn( |
1231 |
| - "set_cursor_manager is Deprecated", |
1232 |
| - DeprecationWarning, |
1233 |
| - stacklevel=2) |
1234 |
| - manager = manager_class(self) |
1235 |
| - if not isinstance(manager, CursorManager): |
1236 |
| - raise TypeError("manager_class must be a subclass of " |
1237 |
| - "CursorManager") |
1238 |
| - |
1239 |
| - self.__cursor_manager = manager |
1240 |
| - |
1241 | 1210 | def _get_topology(self):
|
1242 | 1211 | """Get the internal :class:`~pymongo.topology.Topology` object.
|
1243 | 1212 |
|
@@ -1580,101 +1549,29 @@ def __getitem__(self, name):
|
1580 | 1549 | """
|
1581 | 1550 | return database.Database(self, name)
|
1582 | 1551 |
|
1583 |
| - def close_cursor(self, cursor_id, address=None): |
1584 |
| - """DEPRECATED - Send a kill cursors message soon with the given id. |
1585 |
| -
|
1586 |
| - Raises :class:`TypeError` if `cursor_id` is not an instance of |
1587 |
| - ``(int, long)``. What closing the cursor actually means |
1588 |
| - depends on this client's cursor manager. |
1589 |
| -
|
1590 |
| - This method may be called from a :class:`~pymongo.cursor.Cursor` |
1591 |
| - destructor during garbage collection, so it isn't safe to take a |
1592 |
| - lock or do network I/O. Instead, we schedule the cursor to be closed |
1593 |
| - soon on a background thread. |
1594 |
| -
|
1595 |
| - :Parameters: |
1596 |
| - - `cursor_id`: id of cursor to close |
1597 |
| - - `address` (optional): (host, port) pair of the cursor's server. |
1598 |
| - If it is not provided, the client attempts to close the cursor on |
1599 |
| - the primary or standalone, or a mongos server. |
1600 |
| -
|
1601 |
| - .. versionchanged:: 3.7 |
1602 |
| - Deprecated. |
1603 |
| -
|
1604 |
| - .. versionchanged:: 3.0 |
1605 |
| - Added ``address`` parameter. |
1606 |
| - """ |
1607 |
| - warnings.warn( |
1608 |
| - "close_cursor is deprecated.", |
1609 |
| - DeprecationWarning, |
1610 |
| - stacklevel=2) |
1611 |
| - if not isinstance(cursor_id, integer_types): |
1612 |
| - raise TypeError("cursor_id must be an instance of (int, long)") |
1613 |
| - |
1614 |
| - self._close_cursor(cursor_id, address) |
1615 |
| - |
1616 | 1552 | def _close_cursor(self, cursor_id, address):
|
1617 | 1553 | """Send a kill cursors message with the given id.
|
1618 | 1554 |
|
1619 | 1555 | What closing the cursor actually means depends on this client's
|
1620 | 1556 | cursor manager. If there is none, the cursor is closed asynchronously
|
1621 | 1557 | on a background thread.
|
1622 | 1558 | """
|
1623 |
| - if self.__cursor_manager is not None: |
1624 |
| - self.__cursor_manager.close(cursor_id, address) |
1625 |
| - else: |
1626 |
| - self.__kill_cursors_queue.append((address, [cursor_id])) |
| 1559 | + self.__kill_cursors_queue.append((address, [cursor_id])) |
1627 | 1560 |
|
1628 | 1561 | def _close_cursor_now(self, cursor_id, address=None, session=None):
|
1629 | 1562 | """Send a kill cursors message with the given id.
|
1630 | 1563 |
|
1631 |
| - What closing the cursor actually means depends on this client's |
1632 |
| - cursor manager. If there is none, the cursor is closed synchronously |
1633 |
| - on the current thread. |
| 1564 | + The cursor is closed synchronously on the current thread. |
1634 | 1565 | """
|
1635 | 1566 | if not isinstance(cursor_id, integer_types):
|
1636 | 1567 | raise TypeError("cursor_id must be an instance of (int, long)")
|
1637 | 1568 |
|
1638 |
| - if self.__cursor_manager is not None: |
1639 |
| - self.__cursor_manager.close(cursor_id, address) |
1640 |
| - else: |
1641 |
| - try: |
1642 |
| - self._kill_cursors( |
1643 |
| - [cursor_id], address, self._get_topology(), session) |
1644 |
| - except PyMongoError: |
1645 |
| - # Make another attempt to kill the cursor later. |
1646 |
| - self.__kill_cursors_queue.append((address, [cursor_id])) |
1647 |
| - |
1648 |
| - def kill_cursors(self, cursor_ids, address=None): |
1649 |
| - """DEPRECATED - Send a kill cursors message soon with the given ids. |
1650 |
| -
|
1651 |
| - Raises :class:`TypeError` if `cursor_ids` is not an instance of |
1652 |
| - ``list``. |
1653 |
| -
|
1654 |
| - :Parameters: |
1655 |
| - - `cursor_ids`: list of cursor ids to kill |
1656 |
| - - `address` (optional): (host, port) pair of the cursor's server. |
1657 |
| - If it is not provided, the client attempts to close the cursor on |
1658 |
| - the primary or standalone, or a mongos server. |
1659 |
| -
|
1660 |
| - .. versionchanged:: 3.3 |
1661 |
| - Deprecated. |
1662 |
| -
|
1663 |
| - .. versionchanged:: 3.0 |
1664 |
| - Now accepts an `address` argument. Schedules the cursors to be |
1665 |
| - closed on a background thread instead of sending the message |
1666 |
| - immediately. |
1667 |
| - """ |
1668 |
| - warnings.warn( |
1669 |
| - "kill_cursors is deprecated.", |
1670 |
| - DeprecationWarning, |
1671 |
| - stacklevel=2) |
1672 |
| - |
1673 |
| - if not isinstance(cursor_ids, list): |
1674 |
| - raise TypeError("cursor_ids must be a list") |
1675 |
| - |
1676 |
| - # "Atomic", needs no lock. |
1677 |
| - self.__kill_cursors_queue.append((address, cursor_ids)) |
| 1569 | + try: |
| 1570 | + self._kill_cursors( |
| 1571 | + [cursor_id], address, self._get_topology(), session) |
| 1572 | + except PyMongoError: |
| 1573 | + # Make another attempt to kill the cursor later. |
| 1574 | + self.__kill_cursors_queue.append((address, [cursor_id])) |
1678 | 1575 |
|
1679 | 1576 | def _kill_cursors(self, cursor_ids, address, topology, session):
|
1680 | 1577 | """Send a kill cursors message with the given ids."""
|
|
0 commit comments