diff options
author | adityacp | 2016-08-31 15:30:52 +0530 |
---|---|---|
committer | adityacp | 2016-08-31 15:30:52 +0530 |
commit | 9dbb30e8adadf18e0e5261eda6d1aa6d62fdbb4f (patch) | |
tree | b23b9685fb942266be5c1a748be5e49c0f596c4b /yaksh/xmlrpc_clients.py | |
parent | 40fbb5d8f1d4174f7d7e2d4723e9fbfc40040dcb (diff) | |
parent | aefc8eed3b0c18520059b4005978f1db9cf5591b (diff) | |
download | online_test-9dbb30e8adadf18e0e5261eda6d1aa6d62fdbb4f.tar.gz online_test-9dbb30e8adadf18e0e5261eda6d1aa6d62fdbb4f.tar.bz2 online_test-9dbb30e8adadf18e0e5261eda6d1aa6d62fdbb4f.zip |
rebase with latest changes
Diffstat (limited to 'yaksh/xmlrpc_clients.py')
-rw-r--r-- | yaksh/xmlrpc_clients.py | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/yaksh/xmlrpc_clients.py b/yaksh/xmlrpc_clients.py index 7124550..6bfe0d6 100644 --- a/yaksh/xmlrpc_clients.py +++ b/yaksh/xmlrpc_clients.py @@ -3,6 +3,7 @@ import time import random import socket import json +import urllib from settings import SERVER_PORTS, SERVER_POOL_PORT @@ -21,7 +22,7 @@ class CodeServerProxy(object): """ def __init__(self): pool_url = 'http://localhost:%d' % (SERVER_POOL_PORT) - self.pool_server = ServerProxy(pool_url) + self.pool_url = pool_url def run_code(self, language, test_case_type, json_data, user_dir): """Tests given code (`answer`) with the `test_code` supplied. If the @@ -34,7 +35,7 @@ class CodeServerProxy(object): ---------- json_data contains; user_answer : str - The user's answer for the question. + The user's answer for the question. test_code : str The test code to check the user code with. language : str @@ -57,21 +58,7 @@ class CodeServerProxy(object): return result def _get_server(self): - # Get a suitable server from our pool of servers. This may block. We - # try about 60 times, essentially waiting at most for about 30 seconds. - done, count = False, 60 - - while not done and count > 0: - try: - port = self.pool_server.get_server_port() - except socket.error: - # Wait a while try again. - time.sleep(random.random()) - count -= 1 - else: - done = True - if not done: - raise ConnectionError("Couldn't connect to a server!") + port = json.loads(urllib.urlopen(self.pool_url).read()) proxy = ServerProxy('http://localhost:%d' % port) return proxy |