pbs.py (1385:a80f052561fd) pbs.py (1386:793290a922ee)
1# Copyright (c) 2005 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 16 unchanged lines hidden (view full) ---

25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27# Authors: Nathan Binkert
28
29import os, popen2, re, sys
30
31class MyPOpen(object):
32 def __init__(self, cmd, input = None, output = None, bufsize = -1):
1# Copyright (c) 2005 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 16 unchanged lines hidden (view full) ---

25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27# Authors: Nathan Binkert
28
29import os, popen2, re, sys
30
31class MyPOpen(object):
32 def __init__(self, cmd, input = None, output = None, bufsize = -1):
33 self.sts = -1
33 self.status = -1
34
35 if input is None:
36 p2c_read, p2c_write = os.pipe()
37 self.tochild = os.fdopen(p2c_write, 'w', bufsize)
38 else:
39 p2c_write = None
40 if isinstance(input, file):
41 p2c_read = input.fileno()

--- 17 unchanged lines hidden (view full) ---

59 c2p_write = output.fileno()
60 elif isinstance(output, int):
61 c2p_write = output
62 else:
63 raise AttributeError
64
65 self.pid = os.fork()
66 if self.pid == 0:
34
35 if input is None:
36 p2c_read, p2c_write = os.pipe()
37 self.tochild = os.fdopen(p2c_write, 'w', bufsize)
38 else:
39 p2c_write = None
40 if isinstance(input, file):
41 p2c_read = input.fileno()

--- 17 unchanged lines hidden (view full) ---

59 c2p_write = output.fileno()
60 elif isinstance(output, int):
61 c2p_write = output
62 else:
63 raise AttributeError
64
65 self.pid = os.fork()
66 if self.pid == 0:
67 os.dup2(p2c_read, 0)
68 os.dup2(c2p_write, 1)
69 os.dup2(c2p_write, 2)
70 if isinstance(cmd, basestring):
71 cmd = ['/bin/sh', '-c', cmd]
72 if False:
73 for i in range(3, MAXFD):
74 try:
75 os.close(i)
76 except OSError:
77 pass
67 os.dup2(p2c_read, sys.stdin.fileno())
68 os.dup2(c2p_write, sys.stdout.fileno())
69 os.dup2(c2p_write, sys.stderr.fileno())
78 try:
79 os.execvp(cmd[0], cmd)
80 finally:
81 os._exit(1)
82
83 os.close(p2c_read)
84 os.close(c2p_write)
85
86 def poll(self):
70 try:
71 os.execvp(cmd[0], cmd)
72 finally:
73 os._exit(1)
74
75 os.close(p2c_read)
76 os.close(c2p_write)
77
78 def poll(self):
87 if self.sts < 0:
88 pid, sts = os.waitpid(self.pid, os.WNOHANG)
79 if self.status < 0:
80 pid, status = os.waitpid(self.pid, os.WNOHANG)
89 if pid == self.pid:
81 if pid == self.pid:
90 self.sts = sts
91 return self.sts
82 self.status = status
83 return self.status
92
93 def wait(self):
84
85 def wait(self):
94 if self.sts < 0:
95 pid, sts = os.waitpid(self.pid, 0)
86 if self.status < 0:
87 pid, status = os.waitpid(self.pid, 0)
96 if pid == self.pid:
88 if pid == self.pid:
97 self.sts = sts
98 return self.sts
89 self.status = status
90 return self.status
99
100class qsub:
101 def __init__(self):
102 self.hold = False
103 self.join = False
104 self.keep_stdout = False
105 self.keep_stderr = False
106 self.node_type = ''

--- 78 unchanged lines hidden ---
91
92class qsub:
93 def __init__(self):
94 self.hold = False
95 self.join = False
96 self.keep_stdout = False
97 self.keep_stderr = False
98 self.node_type = ''

--- 78 unchanged lines hidden ---