From: Greg Ercolano <erco@(email surpressed)> Subject: [Q+A] Python Submit script? Date: Sat, 23 Jun 2007 00:32:55 -0400 |
Msg# 1590 View Complete Thread (1 article) | All Threads Last Next |
> Is there an example Rush submit script in Python? Yes, there's a very simple example included with the latest Rush release (102.42a8) in the rush/examples directory; see the simple-submit.py script. If you want a slightly more complex example that shows how to grab the jobid so it can automatically launch irush, see the following. --- snip #!/usr/bin/env python import os import sys import re import tempfile # # Very simple example of how to submit a rush job in python # Tested on Mac OSX 10.4.x with the default version of Python. # if len(sys.argv) == 1: # SUBMIT THE JOB # Save stdout/err to file to later parse jobid # tmp = tempfile.mktemp(".tmp-submit") cmd = "rush -submit > " + tmp + " 2>&1" submit = os.popen(cmd, 'w') submit.write("title PYTHON TEST JOB\n" + "frames 1-10\n" + "logdir -\n" + "command python " + sys.argv[0] + " -render\n" + "cpus +any=5\n") err = submit.close() # GRAB SUBMIT OUTPUT, REMOVE TMP FILE try: out = open(tmp, "r").readlines() print "".join(out) os.remove(tmp) except IOError, (errno,errmsg): print "Can't create tmp file " + tmp + ": " + errmsg sys.exit(0) # SUBMIT FAILED? if err: print "--- SUBMIT FAILED" sys.exit(1) # SUCCESS? PARSE JOBID jobid = re.search("RUSH_JOBID.(\S+)", "\n".join(out)).groups()[0] if jobid == None: sys.stderr.write("-- NO JOBID -- JOB DID NOT SUBMIT\n") sys.exit(1) # LAUNCH IRUSH, SHOW JOB'S FRAMELIST os.system("irush -button Frames " + jobid) sys.exit(0) if sys.argv[1] == "-render" : # RENDER THE JOB # This section is run on each machine. # As an example, we run a 'netstat -rn' command on each machine. # print "--- Working on frame ", os.environ["RUSH_FRAME"] sys.stdout.flush() err = os.system("netstat -rn") if err: print "--- netstat failed: exit code:", (err >> 8) sys.exit(1) # RUSH: FAIL else: print "--- netstat OK: exit code:", (err >> 8) sys.exit(0) # RUSH: OK print "Unknown argument '" + sys.argv[1] + "'" sys.exit(1) --- snip I'm not so hot at Python (yet), so there's probably better ways to do this; comments welcome. For instance, one could probably use the Python "Popen" class, or the older popen3() to avoid the above use of a temp file. Thing is, those pipe functions seemed a bit complicated to use bidirectionally without the possibility of deadlocking, so I went with the temp file approach instead for stability. -- Greg Ercolano, erco@(email surpressed) Rush Render Queue, http://seriss.com/rush/ Tel: (Tel# suppressed) Fax: (Tel# suppressed) Cel: (Tel# suppressed) |