mirror of
https://opendev.org/x/pyghmi
synced 2025-01-28 11:57:34 +00:00
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
This commit is contained in:
parent
130de5483f
commit
b3cbe9bf6e
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user