22
22
import weakref
23
23
from typing import TYPE_CHECKING , Any , Mapping , Optional , cast
24
24
25
- from pymongo import common
25
+ from pymongo import common , periodic_executor
26
26
from pymongo ._csot import MovingMinimum
27
- from pymongo .asynchronous import periodic_executor
28
- from pymongo .asynchronous .periodic_executor import _shutdown_executors
29
27
from pymongo .errors import NetworkTimeout , NotPrimaryError , OperationFailure , _OperationCancelled
30
28
from pymongo .hello import Hello
31
29
from pymongo .lock import _create_lock
32
30
from pymongo .logger import _SDAM_LOGGER , _debug_log , _SDAMStatusMessage
31
+ from pymongo .periodic_executor import _shutdown_executors
33
32
from pymongo .pool_options import _is_faas
34
33
from pymongo .read_preferences import MovingAverage
35
34
from pymongo .server_description import ServerDescription
@@ -76,7 +75,7 @@ async def target() -> bool:
76
75
await monitor ._run () # type:ignore[attr-defined]
77
76
return True
78
77
79
- executor = periodic_executor .PeriodicExecutor (
78
+ executor = periodic_executor .AsyncPeriodicExecutor (
80
79
interval = interval , min_interval = min_interval , target = target , name = name
81
80
)
82
81
@@ -112,9 +111,9 @@ async def close(self) -> None:
112
111
"""
113
112
self .gc_safe_close ()
114
113
115
- def join (self , timeout : Optional [int ] = None ) -> None :
114
+ async def join (self , timeout : Optional [int ] = None ) -> None :
116
115
"""Wait for the monitor to stop."""
117
- self ._executor .join (timeout )
116
+ await self ._executor .join (timeout )
118
117
119
118
def request_check (self ) -> None :
120
119
"""If the monitor is sleeping, wake it soon."""
@@ -139,7 +138,7 @@ def __init__(
139
138
"""
140
139
super ().__init__ (
141
140
topology ,
142
- "pymongo_server_monitor_thread " ,
141
+ "pymongo_server_monitor_task " ,
143
142
topology_settings .heartbeat_frequency ,
144
143
common .MIN_HEARTBEAT_INTERVAL ,
145
144
)
@@ -250,7 +249,7 @@ async def _check_server(self) -> ServerDescription:
250
249
except (OperationFailure , NotPrimaryError ) as exc :
251
250
# Update max cluster time even when hello fails.
252
251
details = cast (Mapping [str , Any ], exc .details )
253
- self ._topology .receive_cluster_time (details .get ("$clusterTime" ))
252
+ await self ._topology .receive_cluster_time (details .get ("$clusterTime" ))
254
253
raise
255
254
except ReferenceError :
256
255
raise
@@ -434,7 +433,7 @@ def __init__(self, topology: Topology, topology_settings: TopologySettings, pool
434
433
"""
435
434
super ().__init__ (
436
435
topology ,
437
- "pymongo_server_rtt_thread " ,
436
+ "pymongo_server_rtt_task " ,
438
437
topology_settings .heartbeat_frequency ,
439
438
common .MIN_HEARTBEAT_INTERVAL ,
440
439
)
@@ -531,4 +530,5 @@ def _shutdown_resources() -> None:
531
530
shutdown ()
532
531
533
532
534
- atexit .register (_shutdown_resources )
533
+ if _IS_SYNC :
534
+ atexit .register (_shutdown_resources )
0 commit comments