<commit_before>import collections
import confluent.interface.console
import confluent.messages as msg
import eventlet
import eventlet.event
import eventlet.greenpool as greenpool
import eventlet.queue
import os
import pyghmi.ipmi.console as console
import pyghmi.ipmi.command as ipmicommand
console.session.select = eventlet.green.select

_ipmithread = None
#pullchain is a pipe to tug on to induce the ipmi thread process pending data
pullchain = None
chainpulled = False
tmptimeout = None
ipmiq = collections.deque([])
ipmiwaiters = collections.deque([])


def wait_on_ipmi():
    waitevt = eventlet.event.Event()
    ipmiwaiters.append(waitevt)
    waitevt.wait()


def _ipmi_evtloop():
    global tmptimeout
    global pullchain
    console.session.Session.register_handle_callback(pullchain[0],
                                                     _process_chgs)
    while (1):
        try:
            if tmptimeout is not None:
                console.session.Session.wait_for_rsp(timeout=tmptimeout)
                tmptimeout = None
            else:
                console.session.Session.wait_for_rsp(timeout=600)
            while ipmiwaiters:
                waiter = ipmiwaiters.popleft()
                waiter.send()
        except RunTimeError:
            raise
        except:
            print "Whoops, that was a doozy"

def _process_chgs(intline):
    #here we receive functions to run in our thread
    #the tuples on the deque consist of:
    #function, arg tuple, and optionally a callback
    #to send the return value back to the requester
    global chainpulled
    os.read(intline,1)  # answer the bell
    chainpulled = False
    try:
        while ipmiq:
            cval = ipmiq.popleft()
            if hasattr(cval[0], '__call__'):
                if isinstance(cval[1], tuple):
                    rv = cval[0](*cval[1])
                elif isinstance(cval[1], dict):
                    rv = cval[0](**cval[1])
                if len(cval) > 2:
                    cval[2](rv)
    except:  # assure the thread does not crash and burn
        print "should put in some debug data here..."



def get_conn_params(node, configdata):
    if 'secret.ipmiuser' in configdata:
        username = configdata['secret.ipmiuser']['value']
    elif 'secret.managementuser' in configdata:
        username = configdata['secret.managementuser']['value']
    else:
        username = 'USERID'
    if 'secret.ipmipassphrase' in configdata:
        passphrase = configdata['secret.ipmipassphrase']['value']
    elif 'secret.managementpassphrase' in configdata:
        passphrase = configdata['secret.managementpassphrase']['value']
    else:<commit_msg>Correct issues in trying to keep ipmi worker alive<commit_after>import collections
import confluent.interface.console
import confluent.messages as msg
import eventlet
import eventlet.event
import eventlet.greenpool as greenpool
import eventlet.queue
import os
import pyghmi.ipmi.console as console
import pyghmi.ipmi.command as ipmicommand
console.session.select = eventlet.green.select

_ipmithread = None
#pullchain is a pipe to tug on to induce the ipmi thread process pending data
pullchain = None
chainpulled = False
tmptimeout = None
ipmiq = collections.deque([])
ipmiwaiters = collections.deque([])


def wait_on_ipmi():
    waitevt = eventlet.event.Event()
    ipmiwaiters.append(waitevt)
    waitevt.wait()


def _ipmi_evtloop():
    global tmptimeout
    global pullchain
    console.session.Session.register_handle_callback(pullchain[0],
                                                     _process_chgs)
    while (1):
        try:
            if tmptimeout is not None:
                console.session.Session.wait_for_rsp(timeout=tmptimeout)
                tmptimeout = None
            else:
                console.session.Session.wait_for_rsp(timeout=600)
            while ipmiwaiters:
                waiter = ipmiwaiters.popleft()
                waiter.send()
        except RuntimeError:
            raise
        except:
            import sys
            print sys.exc_info()[2]

def _process_chgs(intline):
    #here we receive functions to run in our thread
    #the tuples on the deque consist of:
    #function, arg tuple, and optionally a callback
    #to send the return value back to the requester
    global chainpulled
    os.read(intline,1)  # answer the bell
    chainpulled = False
    try:
        while ipmiq:
            cval = ipmiq.popleft()
            if hasattr(cval[0], '__call__'):
                if isinstance(cval[1], tuple):
                    rv = cval[0](*cval[1])
                elif isinstance(cval[1], dict):
                    rv = cval[0](**cval[1])
                if len(cval) > 2:
                    cval[2](rv)
    except:  # assure the thread does not crash and burn
        import sys
        print sys.exc_info()[2]



def get_conn_params(node, configdata):
    if 'secret.ipmiuser' in configdata:
        username = configdata['secret.ipmiuser']['value']
    elif 'secret.managementuser' in configdata:
        username = configdata['secret.managementuser']['value']
    else:
        username = 'USERID'
    if 'secret.ipmipassphrase' in configdata:
        passphrase = configdata['secret.ipmipassphrase']['value']
    elif 'secret.managementpassphrase' in configdata:
        passphrase = configdata['secret.managementpassphrase']['value']
    else:
{'fraction_non_alphanumeric': 0.08595776213412375, 'fraction_numerical': 0.005928121526491293, 'mean_word_length': 2.4127686472819216, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6419301', 'n_tokens_mistral': 1590, 'n_tokens_neox': 1555, 'n_words': 423}