Skip to content

Commit 9a1b545

Browse files
committed
Merge pull request #429 from satra/fix/pending
MRG: fix _is_pending checks
2 parents 92b00b1 + b1774f9 commit 9a1b545

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

nipype/pipeline/plugins/pbs.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import os
55
from time import sleep
6+
import subprocess
67

78
from .base import (SGELikeBatchManagerBase, logger, iflogger, logging)
89

@@ -35,16 +36,12 @@ def __init__(self, **kwargs):
3536
super(PBSPlugin, self).__init__(template, **kwargs)
3637

3738
def _is_pending(self, taskid):
38-
cmd = CommandLine('qstat')
39-
cmd.inputs.args = '%s' % taskid
40-
# check pbs task
41-
oldlevel = iflogger.level
42-
iflogger.setLevel(logging.getLevelName('CRITICAL'))
43-
result = cmd.run(ignore_exception=True)
44-
iflogger.setLevel(oldlevel)
45-
if 'Unknown Job Id' in result.runtime.stderr:
46-
return False
47-
return True
39+
proc = subprocess.Popen(["qstat", taskid],
40+
stdout=subprocess.PIPE,
41+
stderr=subprocess.PIPE)
42+
_, e = proc.communicate()
43+
errmsg = 'Unknown Job Id' # %s' % taskid
44+
return errmsg not in e
4845

4946
def _submit_batchtask(self, scriptfile, node):
5047
cmd = CommandLine('qsub', environ=os.environ.data)

nipype/pipeline/plugins/sge.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
"""
33

44
import os
5+
import subprocess
6+
from time import sleep
57

68
from .base import (SGELikeBatchManagerBase, logger, iflogger, logging)
79

810
from nipype.interfaces.base import CommandLine
911

10-
from time import sleep
1112

1213
class SGEPlugin(SGELikeBatchManagerBase):
1314
"""Execute using SGE (OGE not tested)
@@ -36,16 +37,11 @@ def __init__(self, **kwargs):
3637
super(SGEPlugin, self).__init__(template, **kwargs)
3738

3839
def _is_pending(self, taskid):
39-
cmd = CommandLine('qstat')
40-
cmd.inputs.args = '-j %d' % taskid
41-
# check sge task
42-
oldlevel = iflogger.level
43-
iflogger.setLevel(logging.getLevelName('CRITICAL'))
44-
result = cmd.run(ignore_exception=True)
45-
iflogger.setLevel(oldlevel)
46-
if result.runtime.stdout.startswith('='):
47-
return True
48-
return False
40+
proc = subprocess.Popen(["qstat", '-j', taskid],
41+
stdout=subprocess.PIPE,
42+
stderr=subprocess.PIPE)
43+
o, _ = proc.communicate()
44+
return o.startswith('=')
4945

5046
def _submit_batchtask(self, scriptfile, node):
5147
cmd = CommandLine('qsub', environ=os.environ.data)

0 commit comments

Comments
 (0)