SDKPYTHON-13 Add timeout parameter in Client
diff --git a/docs/source/conf.py b/docs/source/conf.py
index f6489b2..bce5d90 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -51,7 +51,7 @@
 # The short X.Y version.
 version = '0.6'
 # The full version, including alpha/beta/rc tags.
-release = '0.6.2'
+release = '0.6.3'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
diff --git a/predictionio/__init__.py b/predictionio/__init__.py
index cea9547..0c6229f 100644
--- a/predictionio/__init__.py
+++ b/predictionio/__init__.py
@@ -9,7 +9,7 @@
 __copyright__ = "Copyright 2013, TappingStone, Inc."
 __license__ = "Apache License, Version 2.0"
 
-__version__ = "0.6.2"
+__version__ = "0.6.3"
 
 
 # import packages
@@ -121,11 +121,13 @@
             The asynchronous request becomes blocking once this size has been
             reached, until the queued requests are handled.
             Default value is 0, which means infinite queue size.
+    :param timeout: timeout for HTTP connection attempts and requests in seconds (optional).
+            default value is 5.
 
     """
 
     def __init__(self, appkey, threads=1, apiurl="http://localhost:8000",
-                 apiversion="", qsize=0):
+                 apiversion="", qsize=0, timeout=5):
         """Constructor of Client object.
 
         """
@@ -134,6 +136,7 @@
         self.apiurl = apiurl
         self.apiversion = apiversion
         self.qsize = qsize
+        self.timeout = timeout
 
         # check connection type
         https_pattern = r'^https://(.*)'
@@ -149,7 +152,8 @@
 
         self._uid = None  # identified uid
         self._connection = Connection(host=self.host, threads=self.threads,
-                                      qsize=self.qsize, https=self.https)
+                                      qsize=self.qsize, https=self.https,
+                                      timeout=self.timeout)
 
     def close(self):
         """Close this client and the connection.
diff --git a/predictionio/connection.py b/predictionio/connection.py
index 4e2abfc..b3d9df3 100644
--- a/predictionio/connection.py
+++ b/predictionio/connection.py
@@ -157,11 +157,11 @@
 
 class PredictionIOHttpConnection(object):
 
-    def __init__(self, host, https=True):
+    def __init__(self, host, https=True, timeout=5):
         if https:  # https connection
-            self._connection = httplib.HTTPSConnection(host)
+            self._connection = httplib.HTTPSConnection(host, timeout=timeout)
         else:
-            self._connection = httplib.HTTPConnection(host)
+            self._connection = httplib.HTTPConnection(host, timeout=timeout)
 
     def connect(self):
         self._connection.connect()
@@ -245,7 +245,7 @@
         return response  # AsyncResponse object
 
 
-def connection_worker(host, request_queue, https=True, loop=True):
+def connection_worker(host, request_queue, https=True, timeout=5, loop=True):
     """worker function which establishes connection and wait for request jobs
     from the request_queue
 
@@ -257,11 +257,12 @@
                 DELETE
                 KILL
         https: HTTPS (True) or HTTP (False)
+        timeout: timeout for HTTP connection attempts and requests in seconds
         loop: This worker function stays in a loop waiting for request
             For testing purpose only. should always be set to True.
     """
 
-    connect = PredictionIOHttpConnection(host, https)
+    connect = PredictionIOHttpConnection(host, https, timeout)
 
     # loop waiting for job form request queue
     killed = not loop
@@ -307,7 +308,7 @@
     spawn multiple connection_worker threads to handle jobs in the queue q
     """
 
-    def __init__(self, host, threads=1, qsize=0, https=True):
+    def __init__(self, host, threads=1, qsize=0, https=True, timeout=5):
         """constructor
 
         Args:
@@ -315,11 +316,13 @@
             threads: type int, number of threads to be spawn
             qsize: size of the queue q
             https: indicate it is httpS (True) or http connection (False)
+            timeout: timeout for HTTP connection attempts and requests in seconds
         """
         self.host = host
         self.https = https
         self.q = Queue.Queue(qsize)  # if qsize=0, means infinite
         self.threads = threads
+        self.timeout = timeout
         # start thread based on threads number
         self.tid = {}  # dictionary of thread object
 
@@ -327,7 +330,7 @@
             tname = "PredictionIOThread-%s" % i  # thread name
             self.tid[i] = threading.Thread(
                 target=connection_worker, name=tname,
-                args=(self.host, self.q, self.https))
+                kwargs={'host':self.host, 'request_queue':self.q, 'https':self.https, 'timeout':self.timeout})
             self.tid[i].setDaemon(True)
             self.tid[i].start()