Skip to content

Commit 6aca17e

Browse files
committed
Move autograde_wrapper guts into a main() function
This cleans up some warnings
1 parent d3d6168 commit 6aca17e

File tree

1 file changed

+43
-39
lines changed

1 file changed

+43
-39
lines changed

autodriver/autograde_wrapper.py

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,46 +20,50 @@ def __call__(self):
2020
while np is None or np != self.waitfor:
2121
(np, self.status)=os.wait()
2222
except OSError:
23-
if pid:
23+
if np:
2424
print("Chld process {} never exited, but no more children left".format(self.waitfor))
2525
self.status=-1
2626

27-
for f in os.listdir("mount"):
28-
src=os.path.join("mount", f)
29-
dst=os.path.join("autolab", f)
30-
shutil.copy(src, dst)
27+
def main():
28+
for f in os.listdir("mount"):
29+
src=os.path.join("mount", f)
30+
dst=os.path.join("autolab", f)
31+
shutil.copy(src, dst)
3132

32-
autolabuser=pwd.getpwnam("autolab")
33-
(r_p, w_p)=os.pipe()
34-
pid=os.fork()
35-
if pid == 0:
36-
os.close(r_p)
37-
os.setgroups([])
38-
os.setgid(autolabuser.pw_gid)
39-
os.setuid(autolabuser.pw_uid)
40-
args=["autodriver"]
41-
args.extend(sys.argv[1:])
42-
args.append("autolab")
43-
if w_p != 1:
44-
os.dup2(w_p, 1)
45-
if w_p != 2:
46-
os.dup2(w_p, 2)
47-
if w_p > 2:
48-
os.close(w_p)
49-
os.execvp(args[0], args)
50-
os.close(w_p)
51-
waiter=WaitLoop(pid)
52-
thr=threading.Thread(target=waiter)
53-
thr.start()
54-
rpf=os.fdopen(r_p)
55-
shutil.copyfileobj(rpf, open("mount/feedback", "w"))
56-
#print("Copied output")
57-
rpf.close()
58-
thr.join()
59-
# if core, exit -1, else pass through code.
60-
if os.WIFSIGNALED(waiter.status):
61-
status=-1
62-
else:
63-
status=os.WEXITSTATUS(waiter.status)
64-
#print("Status is {}".format(status))
65-
sys.exit(status)
33+
autolabuser=pwd.getpwnam("autolab")
34+
(r_p, w_p)=os.pipe()
35+
pid=os.fork()
36+
if pid == 0:
37+
os.close(r_p)
38+
os.setgroups([])
39+
os.setgid(autolabuser.pw_gid)
40+
os.setuid(autolabuser.pw_uid)
41+
args=["autodriver"]
42+
args.extend(sys.argv[1:])
43+
args.append("autolab")
44+
if w_p != 1:
45+
os.dup2(w_p, 1)
46+
if w_p != 2:
47+
os.dup2(w_p, 2)
48+
if w_p > 2:
49+
os.close(w_p)
50+
os.execvp(args[0], args)
51+
os.close(w_p)
52+
waiter=WaitLoop(pid)
53+
thr=threading.Thread(target=waiter)
54+
thr.start()
55+
rpf=os.fdopen(r_p)
56+
shutil.copyfileobj(rpf, open("mount/feedback", "w"))
57+
#print("Copied output")
58+
rpf.close()
59+
thr.join()
60+
# if core, exit -1, else pass through code.
61+
if os.WIFSIGNALED(waiter.status):
62+
status=-1
63+
else:
64+
status=os.WEXITSTATUS(waiter.status)
65+
#print("Status is {}".format(status))
66+
sys.exit(status)
67+
68+
if __name__ == '__main__':
69+
main()

0 commit comments

Comments
 (0)