Skip to content

Commit 81a98a4

Browse files
author
liubo
committed
fix_lsload_py
1 parent 1f95c07 commit 81a98a4

2 files changed

Lines changed: 32 additions & 9 deletions

File tree

examples/lsload.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
from pythonlsf import lsf
2-
import ctypes
3-
import platform
42

53
def printHostInfo():
64
if lsf.lsb_init("test") > 0:
75
return -1;
86

97
intp_nhosts = lsf.new_intp()
108
lsf.intp_assign(intp_nhosts, 0)
11-
hostsdata = lsf.ls_load(None, intp_nhosts, 0, None)
9+
all_lsload_data = lsf.ls_load_py(None, intp_nhosts, 0, None)
1210
nhosts = lsf.intp_value(intp_nhosts)
13-
all_lsload_data = lsf.hostLoadArray_frompointer(hostsdata)
1411

1512
print("{} hosts in the cluster.".format(nhosts))
1613

1714
for i in range(nhosts) :
1815
host = all_lsload_data[i]
19-
if platform.system() == 'Windows':
20-
print('No.{} host name : {}'.format(i, host.hostName))
21-
else:
22-
hostname = ctypes.cast( host.hostName, ctypes.c_char_p)
23-
print('No.{} host name : {}'.format(i, hostname.value))
16+
print('No.{} host name : {}'.format(i, host.hostName))
2417

2518
return 0
2619

pythonlsf/lsf.i

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,36 @@ PyObject * get_host_load(char *resreq, int index) {
415415
return result;
416416
}
417417

418+
PyObject * ls_load_py(char *resreq, int *numhosts, int options, char *fromhost) {
419+
420+
struct hostLoad * hosts = NULL;
421+
int i = 0, j = 0;
422+
423+
hosts = ls_load(resreq, numhosts, options, fromhost);
424+
425+
if (hosts == NULL) {
426+
ls_perror("ls_load_py");
427+
exit(-1);
428+
}
429+
430+
/* Python3 can not handle dirty string.*/
431+
for (i = 0; i < *numhosts; i++) {
432+
int size_string = sizeof(hosts[i].hostName);
433+
int len_string = strlen(hosts[i].hostName);
434+
for ( j = len_string; j < size_string; j++) hosts[i].hostName[j] = 0;
435+
}
436+
437+
PyObject * result = PyList_New(*numhosts);
438+
for (i = 0; i < *numhosts; i++) {
439+
PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr(&hosts[i]),
440+
SWIGTYPE_p_hostLoad, 0 | 0 );
441+
PyList_SetItem(result,i,o);
442+
}
443+
444+
return result;
445+
}
446+
447+
418448
PyObject * get_queue_info_by_name(char** name, int num) {
419449
struct queueInfoEnt* queueinfo;
420450
int numqueues = num;

0 commit comments

Comments
 (0)