IBM Support

How to read lsb.stream files with LSF Python API?

Question & Answer


Question

LSF provides C APIs to read lsb.stream files. How to implement the same feature using Python API ?

Answer

As of Platform LSF Version 9.1.2, IBM officially supports the Python wrapper for Platform LSF API .

Following code sample shows how to read lsb.stream files (and print certain type of records) using Python APIs

=================================
#! /usr/bin/env python
from pythonlsf import lsf

def display(eventrec):
"""
display event record
"""
if eventrec.type == lsf.EVENT_JOB_NEW:
jobid = eventrec.eventLog.jobNewLog.jobId
fromHost = eventrec.eventLog.jobNewLog.fromHost
queue = eventrec.eventLog.jobNewLog.queue
cwd = eventrec.eventLog.jobNewLog.cwd
print("EVENT_JOB_NEW jobid<%d>, fromHost<%s>, to Queue<%s>, CWD<%s>" %(jobid, fromHost, queue, cwd))
elif eventrec.type == lsf.EVENT_JOB_START:
numHosts = eventrec.eventLog.jobStartLog.numExHosts
execHosts = eventrec.eventLog.jobStartLog.execHosts
hoststr = ""
for i in range(0,numHosts):
hoststr += lsf.stringArray_getitem(execHosts, i) + ""
print("EVENT_JOB_START execHosts<%s>" %(hoststr))
else:
print("event type is %d" %(eventrec.type))

def read_streamrec(path):
"""
read lsb.streams
"""
s = lsf.lsbStream()
s.streamFile = path;
s.maxStreamSize = 1024*1024*1024
s.maxStreamFileNum = 10;

lsf.lsb_openstream(s)

lineNum = lsf.new_intp()
lsf.intp_assign(lineNum, 0)
flag = 1

if lsf.lsb_init("test") > 0:
exit(1)

while flag > 0:
log = lsf.lsb_readstream(lineNum)
if log:
display(log)
else:
flag = 0


if __name__ == '__main__':
print("LSF Clustername is :", lsf.ls_getclustername())
read_streamrec("/<LSF_cluster_Path>/lsb.stream")

=================================

This sample is for feature demo purposes only.

You are encouraged to contribute your own Python wrappers to the open source LSF APIs for Python on GitHub: https://github.com/PlatformLSF/platform-python-lsf-api.

[{"Product":{"code":"SSETD4","label":"Platform LSF"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"--","Platform":[{"code":"PF016","label":"Linux"}],"Version":"9.1.3","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

Modified date:
17 June 2018

UID

isg3T1024720