34
34
import contextlib
35
35
import datetime
36
36
import threading
37
+ import warnings
37
38
import weakref
39
+
38
40
from collections import defaultdict
39
41
40
42
from bson .codec_options import DEFAULT_CODEC_OPTIONS
@@ -358,7 +360,7 @@ def __init__(
358
360
359
361
self .__default_database_name = dbase
360
362
self .__lock = threading .Lock ()
361
- self .__cursor_manager = CursorManager ( self )
363
+ self .__cursor_manager = None
362
364
self .__kill_cursors_queue = []
363
365
364
366
self ._event_listeners = options .pool_options .event_listeners
@@ -712,7 +714,7 @@ def close(self):
712
714
self ._topology .close ()
713
715
714
716
def set_cursor_manager (self , manager_class ):
715
- """Set this client's cursor manager.
717
+ """DEPRECATED - Set this client's cursor manager.
716
718
717
719
Raises :class:`TypeError` if `manager_class` is not a subclass of
718
720
:class:`~pymongo.cursor_manager.CursorManager`. A cursor manager
@@ -723,9 +725,16 @@ def set_cursor_manager(self, manager_class):
723
725
:Parameters:
724
726
- `manager_class`: cursor manager to use
725
727
728
+ .. versionchanged:: 3.3
729
+ Deprecated, for real this time.
730
+
726
731
.. versionchanged:: 3.0
727
732
Undeprecated.
728
733
"""
734
+ warnings .warn (
735
+ "set_cursor_manager is Deprecated" ,
736
+ DeprecationWarning ,
737
+ stacklevel = 2 )
729
738
manager = manager_class (self )
730
739
if not isinstance (manager , CursorManager ):
731
740
raise TypeError ("manager_class must be a subclass of "
@@ -920,12 +929,17 @@ def __getitem__(self, name):
920
929
return database .Database (self , name )
921
930
922
931
def close_cursor (self , cursor_id , address = None ):
923
- """Close a single database cursor .
932
+ """Send a kill cursors message soon with the given id .
924
933
925
934
Raises :class:`TypeError` if `cursor_id` is not an instance of
926
935
``(int, long)``. What closing the cursor actually means
927
936
depends on this client's cursor manager.
928
937
938
+ This method may be called from a :class:`~pymongo.cursor.Cursor`
939
+ destructor during garbage collection, so it isn't safe to take a
940
+ lock or do network I/O. Instead, we schedule the cursor to be closed
941
+ soon on a background thread.
942
+
929
943
:Parameters:
930
944
- `cursor_id`: id of cursor to close
931
945
- `address` (optional): (host, port) pair of the cursor's server.
@@ -938,30 +952,36 @@ def close_cursor(self, cursor_id, address=None):
938
952
if not isinstance (cursor_id , integer_types ):
939
953
raise TypeError ("cursor_id must be an instance of (int, long)" )
940
954
941
- self .__cursor_manager .close (cursor_id , address )
955
+ if self .__cursor_manager is not None :
956
+ self .__cursor_manager .close (cursor_id , address )
957
+ else :
958
+ self .__kill_cursors_queue .append ((address , [cursor_id ]))
942
959
943
960
def kill_cursors (self , cursor_ids , address = None ):
944
- """Send a kill cursors message soon with the given ids.
961
+ """DEPRECATED - Send a kill cursors message soon with the given ids.
945
962
946
963
Raises :class:`TypeError` if `cursor_ids` is not an instance of
947
964
``list``.
948
965
949
- This method may be called from a :class:`~pymongo.cursor.Cursor`
950
- destructor during garbage collection, so it isn't safe to take a
951
- lock or do network I/O. Instead, we schedule the cursor to be closed
952
- soon on a background thread.
953
-
954
966
:Parameters:
955
967
- `cursor_ids`: list of cursor ids to kill
956
968
- `address` (optional): (host, port) pair of the cursor's server.
957
969
If it is not provided, the client attempts to close the cursor on
958
970
the primary or standalone, or a mongos server.
959
971
972
+ .. versionchanged:: 3.3
973
+ Deprecated.
974
+
960
975
.. versionchanged:: 3.0
961
976
Now accepts an `address` argument. Schedules the cursors to be
962
977
closed on a background thread instead of sending the message
963
978
immediately.
964
979
"""
980
+ warnings .warn (
981
+ "kill_cursors is deprecated." ,
982
+ DeprecationWarning ,
983
+ stacklevel = 2 )
984
+
965
985
if not isinstance (cursor_ids , list ):
966
986
raise TypeError ("cursor_ids must be a list" )
967
987
0 commit comments