|
22 | 22 |
|
23 | 23 | from __future__ import absolute_import, print_function, unicode_literals |
24 | 24 |
|
| 25 | +import sys |
25 | 26 | from collections import namedtuple |
26 | 27 | from ctypes import byref, c_int, create_string_buffer, pointer, POINTER, sizeof |
27 | 28 |
|
|
50 | 51 | py_drmaa_exit, py_drmaa_init) |
51 | 52 |
|
52 | 53 |
|
| 54 | +# Python 3 compatability help |
| 55 | +if sys.version_info < (3, 0): |
| 56 | + bytes = str |
| 57 | + str = unicode |
| 58 | + |
| 59 | + |
53 | 60 | JobInfo = namedtuple("JobInfo", |
54 | 61 | """jobId hasExited hasSignal terminatedSignal hasCoreDump |
55 | 62 | wasAborted exitStatus resourceUsage""") |
@@ -368,8 +375,8 @@ def control(jobId, operation): |
368 | 375 | jobs submitted by other DRMAA session in other DRMAA implementations |
369 | 376 | or jobs submitted via native utilities. |
370 | 377 | """ |
371 | | - if not isinstance(jobId, bytes): |
372 | | - jobId = jobId.encode() |
| 378 | + if isinstance(jobId, str): |
| 379 | + jobId = jobId.encode() |
373 | 380 | c(drmaa_control, jobId, string_to_control_action(operation)) |
374 | 381 |
|
375 | 382 | # takes string list, num value and boolean, no return value |
@@ -453,9 +460,9 @@ def wait(jobId, timeout=-1): |
453 | 460 | stat = c_int() |
454 | 461 | jid_out = create_string_buffer(128) |
455 | 462 | rusage = pointer(POINTER(drmaa_attr_values_t)()) |
456 | | - if not isinstance(jobId, bytes): |
457 | | - jobId = jobId.encode() |
458 | | - c(drmaa_wait, jobId, jid_out, sizeof(jid_out), byref(stat), timeout, |
| 463 | + if isinstance(jobId, str): |
| 464 | + jobId = jobId.encode() |
| 465 | + c(drmaa_wait, jobId, jid_out, sizeof(jid_out), byref(stat), timeout, |
459 | 466 | rusage) |
460 | 467 | res_usage = adapt_rusage(rusage) |
461 | 468 | exited = c_int() |
@@ -501,8 +508,8 @@ def jobStatus(jobId): |
501 | 508 | jobs return a FAILED status. |
502 | 509 | """ |
503 | 510 | status = c_int() |
504 | | - if not isinstance(jobId, bytes): |
505 | | - jobId = jobId.encode() |
| 511 | + if isinstance(jobId, str): |
| 512 | + jobId = jobId.encode() |
506 | 513 | c(drmaa_job_ps, jobId, byref(status)) |
507 | 514 | return status_to_string(status.value) |
508 | 515 |
|
|
0 commit comments