3
3
"""
4
4
from __future__ import print_function , division , unicode_literals , absolute_import
5
5
6
- from builtins import object
6
+ from builtins import object , str , bytes
7
7
8
8
import os
9
9
import pwd
18
18
from ...interfaces .base import CommandLine
19
19
from .base import (SGELikeBatchManagerBase , logger , iflogger , logging )
20
20
21
- DEBUGGING_PREFIX = str ( int ( random .uniform (100 , 999 ) ))
21
+ DEBUGGING_PREFIX = '{0!d}' . format ( random .uniform (100 , 999 ))
22
22
23
23
24
24
def sge_debug_print (message ):
25
25
""" Needed for debugging on big jobs. Once this is fully vetted, it can be removed.
26
26
"""
27
- logger .debug (DEBUGGING_PREFIX + " " + "=!" * 3 + " " + message )
27
+ logger .debug ('%s ' + '=!' * 3 + ' %s' , DEBUGGING_PREFIX , message )
28
28
# print DEBUGGING_PREFIX + " " + "=!" * 3 + " " + message
29
29
30
30
@@ -40,8 +40,7 @@ def __init__(self, job_num, job_queue_state, job_time, job_queue_name, job_slots
40
40
self ._job_num = int (
41
41
job_num ) # The primary unique identifier for this job, must be an integer!
42
42
# self._jobOwn = None # Who owns this job
43
- self ._job_queue_state = str (
44
- job_queue_state ) # ["running","zombie",...??]
43
+ self ._job_queue_state = '%s' % job_queue_state # ["running","zombie",...??]
45
44
# self._jobActionState = str(jobActionState) # ['r','qw','S',...??]
46
45
self ._job_time = job_time # The job start time
47
46
self ._job_info_creation_time = time .time (
@@ -51,12 +50,10 @@ def __init__(self, job_num, job_queue_state, job_time, job_queue_name, job_slots
51
50
self ._qsub_command_line = qsub_command_line
52
51
53
52
def __repr__ (self ):
54
- return str (self ._job_num ).ljust (8 ) \
55
- + str (self ._job_queue_state ).ljust (12 ) \
56
- + str (self ._job_slots ).ljust (3 ) \
57
- + time .strftime ("%Y-%m-%dT%H:%M:%S" , time .gmtime (self ._job_time )).ljust (20 ) \
58
- + str (self ._job_queue_name ).ljust (8 ) \
59
- + str (self ._qsub_command_line )
53
+ return '{:<8d}{:12}{:<3d}{:20}{:8}{}' .format (
54
+ self ._job_num , self ._queue_state , self ._job_slots ,
55
+ time .strftime ("%Y-%m-%dT%H:%M:%S" , time .gmtime (self ._job_time )),
56
+ self ._job_queue_name , self ._qsub_command_line )
60
57
61
58
def is_initializing (self ):
62
59
return self ._job_queue_state == "initializing"
@@ -150,12 +147,13 @@ def _qacct_verified_complete(taskid):
150
147
while qacct_retries > 0 :
151
148
qacct_retries -= 1
152
149
try :
150
+ strtaskid = '{0!d}' .format (taskid )
153
151
proc = subprocess .Popen (
154
- [this_command , '-o' , pwd .getpwuid (os .getuid ())[0 ], '-j' , str ( taskid ) ],
152
+ [this_command , '-o' , pwd .getpwuid (os .getuid ())[0 ], '-j' , strtaskid ],
155
153
stdout = subprocess .PIPE ,
156
154
stderr = subprocess .PIPE )
157
155
qacct_result , _ = proc .communicate ()
158
- if qacct_result .find (str ( taskid ) ):
156
+ if qacct_result .find (strtaskid ):
159
157
is_complete = True
160
158
sge_debug_print (
161
159
"NOTE: qacct for jobs\n {0}" .format (qacct_result ))
@@ -276,7 +274,7 @@ def _run_qstat(self, reason_for_qstat, force_instant=True):
276
274
def print_dictionary (self ):
277
275
"""For debugging"""
278
276
for vv in list (self ._task_dictionary .values ()):
279
- sge_debug_print (str ( vv ) )
277
+ sge_debug_print ('%s' % vv )
280
278
281
279
def is_job_pending (self , task_id ):
282
280
task_id = int (task_id ) # Ensure that it is an integer
@@ -398,7 +396,7 @@ def _submit_batchtask(self, scriptfile, node):
398
396
oldlevel = iflogger .level
399
397
iflogger .setLevel (logging .getLevelName ('CRITICAL' ))
400
398
tries = 0
401
- result = list ()
399
+ result = None
402
400
while True :
403
401
try :
404
402
result = cmd .run ()
@@ -409,9 +407,8 @@ def _submit_batchtask(self, scriptfile, node):
409
407
self ._retry_timeout ) # sleep 2 seconds and try again.
410
408
else :
411
409
iflogger .setLevel (oldlevel )
412
- raise RuntimeError ('\n ' .join ((('Could not submit sge task'
413
- ' for node %s' ) % node ._id ,
414
- str (e ))))
410
+ raise RuntimeError (
411
+ 'Could not submit sge task for node %s\n %s' % (node ._id , e ))
415
412
else :
416
413
break
417
414
iflogger .setLevel (oldlevel )
@@ -421,6 +418,6 @@ def _submit_batchtask(self, scriptfile, node):
421
418
lines [- 1 ]).groups ()[0 ])
422
419
self ._pending [taskid ] = node .output_dir ()
423
420
self ._refQstatSubstitute .add_startup_job (taskid , cmd .cmdline )
424
- logger .debug ('submitted sge task: %d for node %s with %s' %
425
- ( taskid , node ._id , cmd .cmdline ) )
421
+ logger .debug ('submitted sge task: %d for node %s with %s' ,
422
+ taskid , node ._id , cmd .cmdline )
426
423
return taskid
0 commit comments