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