From b3cbe9bf6ed15f9166f9d665c1f27a587fc7cd46 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 17 Aug 2018 14:47:09 -0400 Subject: [PATCH] Add a maintenance thread Make it easier to cope with burdens of long running execution by providing a single-shot call to establish a persistent context to run keepalives from. Change-Id: I5ddbd647846daf119a4219d5c014682223657dfd --- pyghmi/ipmi/command.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pyghmi/ipmi/command.py b/pyghmi/ipmi/command.py index 6e26641a..4237cedf 100644 --- a/pyghmi/ipmi/command.py +++ b/pyghmi/ipmi/command.py @@ -36,6 +36,7 @@ import pyghmi.ipmi.private.util as pygutil import pyghmi.ipmi.sdr as sdr import socket import struct +import threading try: range = xrange @@ -95,6 +96,19 @@ def _mask_to_cidr(mask): def _cidr_to_mask(prefix): return struct.pack('>I', 2 ** prefix - 1 << (32 - prefix)) +class Housekeeper(threading.Thread): + """A Maintenance thread for housekeeping + + Long lived use of pyghmi may warrant some recurring asynchronous behavior. + This stock thread provides a simple minimal context for these housekeeping + tasks to run in. To use, do 'pyghmi.ipmi.command.Maintenance().start()' + and from that point forward, pyghmi should execute any needed ongoing + tasks automatically as needed. This is an alternative to calling + wait_for_rsp or eventloop in a thread of the callers design. + """ + def run(self): + Command.eventloop() + class Command(object): """Send IPMI commands to BMCs. @@ -172,8 +186,8 @@ class Command(object): @classmethod def eventloop(cls): - while session.Session.wait_for_rsp(): - pass + while True: + session.Session.wait_for_rsp() @classmethod def wait_for_rsp(cls, timeout):