From 21976d997657bacb45be9e205667c79a7cd7657e Mon Sep 17 00:00:00 2001 From: "A. Jesse Jiryu Davis" Date: Fri, 31 Oct 2014 22:10:20 -0400 Subject: [PATCH] Monitors stop themselves when the Topology is GC'ed. --- pymongo/monitor.py | 7 ++++++- test/test_monitor.py | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pymongo/monitor.py b/pymongo/monitor.py index 616e7345a..f15f9a2dc 100644 --- a/pymongo/monitor.py +++ b/pymongo/monitor.py @@ -44,7 +44,12 @@ class Monitor(object): """ super(Monitor, self).__init__() self._server_description = server_description - self._topology = weakref.proxy(topology) + + # A weakref callback, takes ref to the dead topology as its parameter. + def close(dummy): + self.close() + + self._topology = weakref.proxy(topology, close) self._pool = pool self._settings = topology_settings self._stopped = False diff --git a/test/test_monitor.py b/test/test_monitor.py index cb426775c..11b836399 100644 --- a/test/test_monitor.py +++ b/test/test_monitor.py @@ -49,7 +49,6 @@ class TestMonitor(IntegrationTest): ref = wait_until(partial(find_monitor_ref, monitor), 'register monitor') - client.close() del monitor del client