summaryrefslogtreecommitdiff
path: root/python_server.py
diff options
context:
space:
mode:
authorPrabhu Ramachandran2011-11-19 14:08:56 +0530
committerPrabhu Ramachandran2011-11-19 14:08:56 +0530
commit759d1da9a8e8221f999550042fbcb96ac5083607 (patch)
tree2804d6f1b6a8fcb3d5d4a6998aa6d98a3808d01d /python_server.py
parent6fcc55a442d52c251408566f6bc924b15cef0bb3 (diff)
downloadonline_test-759d1da9a8e8221f999550042fbcb96ac5083607.tar.gz
online_test-759d1da9a8e8221f999550042fbcb96ac5083607.tar.bz2
online_test-759d1da9a8e8221f999550042fbcb96ac5083607.zip
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.
Diffstat (limited to 'python_server.py')
-rwxr-xr-xpython_server.py12
1 files 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()