diff options
author | ankitjavalkar | 2016-08-16 20:26:03 +0530 |
---|---|---|
committer | GitHub | 2016-08-16 20:26:03 +0530 |
commit | e1e299b671a19b65705fb256d282e1e802a4c051 (patch) | |
tree | a0759c69b03febe2b0e43520e0bd9efd4384f681 /yaksh/xmlrpc_clients.py | |
parent | 50c3008096f5f02a036d8d9a5cbfe9cc43ff0823 (diff) | |
parent | edaffc172a6cf1fcae7e5e3cae16e5aaf84c996b (diff) | |
download | online_test-e1e299b671a19b65705fb256d282e1e802a4c051.tar.gz online_test-e1e299b671a19b65705fb256d282e1e802a4c051.tar.bz2 online_test-e1e299b671a19b65705fb256d282e1e802a4c051.zip |
Merge pull request #124 from FOSSEE/test-code-server
Improve server pool
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 |