job.py (1712:3bb2f82d705c) job.py (1816:ecb6cb1337e8)
1#!/usr/bin/env python
2# Copyright (c) 2005 The Regents of The University of Michigan
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;

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

78def readval(filename):
79 file = open(filename, 'r')
80 value = file.readline().strip()
81 file.close()
82 return value
83
84if __name__ == '__main__':
85 rootdir = env.setdefault('ROOTDIR', os.getcwd())
1#!/usr/bin/env python
2# Copyright (c) 2005 The Regents of The University of Michigan
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met: redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer;

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

78def readval(filename):
79 file = open(filename, 'r')
80 value = file.readline().strip()
81 file.close()
82 return value
83
84if __name__ == '__main__':
85 rootdir = env.setdefault('ROOTDIR', os.getcwd())
86 jobid = env['PBS_JOBID']
87 jobname = env['PBS_JOBNAME']
88 jobdir = joinpath(rootdir, jobname)
86 pbs_jobid = env['PBS_JOBID']
87 pbs_jobname = env['PBS_JOBNAME']
89 basedir = joinpath(rootdir, 'Base')
88 basedir = joinpath(rootdir, 'Base')
90 user = env['USER']
91
89 jobname = env.setdefault('JOBNAME', pbs_jobname)
90 jobfile = env.setdefault('JOBFILE', joinpath(basedir, 'test.py'))
91 outdir = env.setdefault('OUTPUT_DIR', joinpath(rootdir, jobname))
92 env['POOLJOB'] = 'True'
92 env['POOLJOB'] = 'True'
93 env['OUTPUT_DIR'] = jobdir
94 env['JOBFILE'] = joinpath(basedir, 'test.py')
95 env['JOBNAME'] = jobname
96
93
94 if os.path.isdir("/work"):
95 workbase = "/work"
96 else:
97 workbase = "/tmp/"
98
99 workdir = joinpath(workbase, '%s.%s' % (env['USER'], pbs_jobid))
100
97 def echofile(filename, string):
98 try:
101 def echofile(filename, string):
102 try:
99 f = file(joinpath(jobdir, filename), 'w')
103 f = file(joinpath(outdir, filename), 'w')
100 print >>f, string
101 f.flush()
102 f.close()
103 except IOError,e:
104 sys.exit(e)
105
104 print >>f, string
105 f.flush()
106 f.close()
107 except IOError,e:
108 sys.exit(e)
109
106 if os.path.isdir("/work"):
107 workbase = "/work"
108 else:
109 workbase = "/tmp/"
110
111 workdir = joinpath(workbase, '%s.%s' % (user, jobid))
112
113 os.umask(0022)
114
115 echofile('.start', date())
110 os.umask(0022)
111
112 echofile('.start', date())
116 echofile('.jobid', jobid)
113 echofile('.pbs_jobid', pbs_jobid)
114 echofile('.pbs_jobname', pbs_jobid)
117 echofile('.host', socket.gethostname())
118
119 if os.path.isdir(workdir):
120 cleandir(workdir)
121 else:
122 os.mkdir(workdir)
123
124 if os.path.isdir('/z/dist'):
125 sync = rsync()
126 sync.delete = True
127 sync.sudo = True
128 sync.do('poolfs::dist/m5/', '/z/dist/m5/')
129
130 try:
131 os.chdir(workdir)
132 except OSError,e:
133 sys.exit(e)
134
115 echofile('.host', socket.gethostname())
116
117 if os.path.isdir(workdir):
118 cleandir(workdir)
119 else:
120 os.mkdir(workdir)
121
122 if os.path.isdir('/z/dist'):
123 sync = rsync()
124 sync.delete = True
125 sync.sudo = True
126 sync.do('poolfs::dist/m5/', '/z/dist/m5/')
127
128 try:
129 os.chdir(workdir)
130 except OSError,e:
131 sys.exit(e)
132
135 os.symlink(joinpath(jobdir, 'output'), 'status.out')
133 os.symlink(joinpath(outdir, 'output'), 'status.out')
136
137 args = [ joinpath(basedir, 'm5'), joinpath(basedir, 'run.py') ]
138 if not len(args):
139 sys.exit("no arguments")
140
141 print 'starting job... %s' % date()
142 print ' '.join(args)
143 print
144 sys.stdout.flush()
145
146 childpid = os.fork()
147 if not childpid:
148 # Execute command
149 sys.stdin.close()
134
135 args = [ joinpath(basedir, 'm5'), joinpath(basedir, 'run.py') ]
136 if not len(args):
137 sys.exit("no arguments")
138
139 print 'starting job... %s' % date()
140 print ' '.join(args)
141 print
142 sys.stdout.flush()
143
144 childpid = os.fork()
145 if not childpid:
146 # Execute command
147 sys.stdin.close()
150 fd = os.open(joinpath(jobdir, "output"),
148 fd = os.open(joinpath(outdir, "output"),
151 os.O_WRONLY | os.O_CREAT | os.O_TRUNC)
152 os.dup2(fd, sys.stdout.fileno())
153 os.dup2(fd, sys.stderr.fileno())
154 os.execvp(args[0], args)
155
156 def handler(signum, frame):
157 if childpid != 0:
158 os.kill(childpid, signum)

--- 25 unchanged lines hidden ---
149 os.O_WRONLY | os.O_CREAT | os.O_TRUNC)
150 os.dup2(fd, sys.stdout.fileno())
151 os.dup2(fd, sys.stderr.fileno())
152 os.execvp(args[0], args)
153
154 def handler(signum, frame):
155 if childpid != 0:
156 os.kill(childpid, signum)

--- 25 unchanged lines hidden ---