From 759d1da9a8e8221f999550042fbcb96ac5083607 Mon Sep 17 00:00:00 2001 From: Prabhu Ramachandran Date: Sat, 19 Nov 2011 14:08:56 +0530 Subject: Setting timeout to 2 and refactoring a little Setting default timeout to 2 seconds. Also made the run_as_nobody a function so the rest of the server can be tested without the need to sudo it. --- python_server.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/python_server.py b/python_server.py index 6ade0ff..dee5631 100755 --- a/python_server.py +++ b/python_server.py @@ -12,12 +12,13 @@ from os.path import isdir import signal # Timeout for the code to run in seconds. -TIMEOUT = 3 +TIMEOUT = 2 -# Set the effective uid -nobody = pwd.getpwnam('nobody') -os.setegid(nobody.pw_gid) -os.seteuid(nobody.pw_uid) +def run_as_nobody(): + # Set the effective uid + nobody = pwd.getpwnam('nobody') + os.setegid(nobody.pw_gid) + os.seteuid(nobody.pw_uid) # Raised when the code times-out. # c.f. http://pguides.net/python/timeout-a-function @@ -82,6 +83,7 @@ def run_code(answer, test_code, in_dir=None): def main(): + run_as_nobody() server = SimpleXMLRPCServer(("localhost", 8001)) server.register_function(run_code) server.serve_forever() -- cgit