PYTHON-975 - Name our threads
This commit is contained in:
parent
fe5c119ca4
commit
164cc34320
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user