diff --git a/pymongo/mongo_client.py b/pymongo/mongo_client.py index dcba068f6..c89920d38 100644 --- a/pymongo/mongo_client.py +++ b/pymongo/mongo_client.py @@ -376,7 +376,8 @@ class MongoClient(common.BaseObject): condition_class=self._topology_settings.condition_class, interval=common.KILL_CURSOR_FREQUENCY, min_interval=0, - target=target) + target=target, + name="pymongo_kill_cursors_thread") # We strongly reference the executor and it weakly references us via # this closure. When the client is freed, stop the executor soon. diff --git a/pymongo/monitor.py b/pymongo/monitor.py index 0967d15f3..375e8cad6 100644 --- a/pymongo/monitor.py +++ b/pymongo/monitor.py @@ -58,7 +58,8 @@ class Monitor(object): condition_class=self._settings.condition_class, interval=common.HEARTBEAT_FREQUENCY, min_interval=common.MIN_HEARTBEAT_INTERVAL, - target=target) + target=target, + name="pymongo_server_monitor_thread") self._executor = executor diff --git a/pymongo/periodic_executor.py b/pymongo/periodic_executor.py index d919b3727..84a4fefa9 100644 --- a/pymongo/periodic_executor.py +++ b/pymongo/periodic_executor.py @@ -24,7 +24,8 @@ from pymongo.monotonic import time as _time class PeriodicExecutor(object): - def __init__(self, condition_class, interval, min_interval, target): + def __init__( + self, condition_class, interval, min_interval, target, name=None): """"Run a target function periodically on a background thread. If the target's return value is false, the executor stops. @@ -35,6 +36,7 @@ class PeriodicExecutor(object): - `min_interval`: Minimum seconds between calls if `wake` is called very often. - `target`: A function. + - `name`: A name to give the underlying thread. """ self._event = thread_util.Event(condition_class) self._interval = interval @@ -42,6 +44,7 @@ class PeriodicExecutor(object): self._target = target self._stopped = False self._thread = None + self._name = name def open(self): """Start. Multiple calls have no effect. @@ -57,7 +60,7 @@ class PeriodicExecutor(object): pass if not started: - thread = threading.Thread(target=self._run) + thread = threading.Thread(target=self._run, name=self._name) thread.daemon = True self._thread = weakref.proxy(thread) _register_executor(self)