Skip to content

Commit dcbb1fa

Browse files
committed
target: Quieten resource disappearing
Quietens a resource disappearing if it has no active clients. In this way, if all the drivers using a resource are deactivated before the resource disappears, no message will be shown on stdout, keeping the output clean. Signed-off-by: Joshua Watt <Joshua.Watt@garmin.com>
1 parent ee9fe32 commit dcbb1fa

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

labgrid/target.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,15 @@ def update_resources(self):
5151
for resource in self.resources:
5252
resource.poll()
5353
if not resource.avail and resource.state is BindingState.active:
54-
self.log.info("deactivating unavailable resource %s", resource.display_name) # pylint: disable=line-too-long
55-
self.deactivate(resource)
54+
deactivated = self.deactivate(resource)
55+
deactivated.remove(resource)
56+
if deactivated:
57+
self.log.info("deactivating unavailable resource %s used by %s",
58+
resource.display_name,
59+
", ".join(d.display_name for d in deactivated)
60+
)
61+
else:
62+
self.log.debug("deactivating unavailable resource %s (unused)", resource.display_name) # pylint: disable=line-too-long
5663

5764
def await_resources(self, resources, timeout=None, avail=True):
5865
"""
@@ -438,6 +445,8 @@ def deactivate(self, client, name=None):
438445
Recursively deactivate the client's clients and itself.
439446
440447
This is needed to ensure that no client has an inactive supplier.
448+
449+
Returns the list of all objects that were deactivated
441450
"""
442451
if isinstance(client, str):
443452
cls = target_factory.class_from_string(client)
@@ -446,7 +455,7 @@ def deactivate(self, client, name=None):
446455
assert client is not None
447456

448457
if client.state is BindingState.bound:
449-
return # nothing to do
458+
return [] # nothing to do
450459

451460
if client.state is not BindingState.active:
452461
raise BindingError(
@@ -456,12 +465,15 @@ def deactivate(self, client, name=None):
456465
# consistency check
457466
assert client in self.resources or client in self.drivers
458467

468+
deactivated = [client]
469+
459470
for cli in client.clients:
460-
self.deactivate(cli)
471+
deactivated.extend(self.deactivate(cli))
461472

462473
# update state
463474
client.on_deactivate()
464475
client.state = BindingState.bound
476+
return deactivated
465477

466478
def deactivate_all_drivers(self):
467479
"""Deactivates all drivers in reversed order they were activated"""

0 commit comments

Comments
 (0)