Skip to content

Commit 164cc34

Browse files
committed
PYTHON-975 - Name our threads
1 parent fe5c119 commit 164cc34

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

pymongo/mongo_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ def target():
376376
condition_class=self._topology_settings.condition_class,
377377
interval=common.KILL_CURSOR_FREQUENCY,
378378
min_interval=0,
379-
target=target)
379+
target=target,
380+
name="pymongo_kill_cursors_thread")
380381

381382
# We strongly reference the executor and it weakly references us via
382383
# this closure. When the client is freed, stop the executor soon.

pymongo/monitor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def target():
5858
condition_class=self._settings.condition_class,
5959
interval=common.HEARTBEAT_FREQUENCY,
6060
min_interval=common.MIN_HEARTBEAT_INTERVAL,
61-
target=target)
61+
target=target,
62+
name="pymongo_server_monitor_thread")
6263

6364
self._executor = executor
6465

pymongo/periodic_executor.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525

2626
class PeriodicExecutor(object):
27-
def __init__(self, condition_class, interval, min_interval, target):
27+
def __init__(
28+
self, condition_class, interval, min_interval, target, name=None):
2829
""""Run a target function periodically on a background thread.
2930
3031
If the target's return value is false, the executor stops.
@@ -35,13 +36,15 @@ def __init__(self, condition_class, interval, min_interval, target):
3536
- `min_interval`: Minimum seconds between calls if `wake` is
3637
called very often.
3738
- `target`: A function.
39+
- `name`: A name to give the underlying thread.
3840
"""
3941
self._event = thread_util.Event(condition_class)
4042
self._interval = interval
4143
self._min_interval = min_interval
4244
self._target = target
4345
self._stopped = False
4446
self._thread = None
47+
self._name = name
4548

4649
def open(self):
4750
"""Start. Multiple calls have no effect.
@@ -57,7 +60,7 @@ def open(self):
5760
pass
5861

5962
if not started:
60-
thread = threading.Thread(target=self._run)
63+
thread = threading.Thread(target=self._run, name=self._name)
6164
thread.daemon = True
6265
self._thread = weakref.proxy(thread)
6366
_register_executor(self)

0 commit comments

Comments
 (0)