@@ -133,6 +133,21 @@ class RemoteConnection(object):
133
133
134
134
Communicates with the server using the WebDriver wire protocol:
135
135
https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol"""
136
+
137
+ _timeout = socket ._GLOBAL_DEFAULT_TIMEOUT
138
+
139
+ @classmethod
140
+ def get_timeout (cls ):
141
+ return None if cls ._timeout == socket ._GLOBAL_DEFAULT_TIMEOUT or cls ._timeout
142
+
143
+ @classmethod
144
+ def set_timeout (cls , timeout ):
145
+ cls ._timeout = timeout
146
+
147
+ @classmethod
148
+ def reset_timeout (cls ):
149
+ cls ._timeout = socket ._GLOBAL_DEFAULT_TIMEOUT
150
+
136
151
def __init__ (self , remote_server_addr , keep_alive = False ):
137
152
# Attempt to resolve the hostname and get an IP address.
138
153
self .keep_alive = keep_alive
@@ -157,7 +172,9 @@ def __init__(self, remote_server_addr, keep_alive=False):
157
172
158
173
self ._url = remote_server_addr
159
174
if keep_alive :
160
- self ._conn = httplib .HTTPConnection (str (addr ), str (parsed_url .port ))
175
+ self ._conn = httplib .HTTPConnection (
176
+ str (addr ), str (parsed_url .port ), timeout = self ._timeout )
177
+
161
178
self ._commands = {
162
179
Command .STATUS : ('GET' , '/status' ),
163
180
Command .NEW_SESSION : ('POST' , '/session' ),
@@ -386,7 +403,7 @@ def _request(self, method, url, body=None):
386
403
try :
387
404
self ._conn .request (method , parsed_url .path , body , headers )
388
405
resp = self ._conn .getresponse ()
389
- except httplib .HTTPException :
406
+ except ( httplib .HTTPException , socket . error ) :
390
407
self ._conn .close ()
391
408
raise
392
409
@@ -422,7 +439,7 @@ def _request(self, method, url, body=None):
422
439
else :
423
440
opener = url_request .build_opener (url_request .HTTPRedirectHandler (),
424
441
HttpErrorHandler ())
425
- resp = opener .open (request )
442
+ resp = opener .open (request , timeout = self . _timeout )
426
443
statuscode = resp .code
427
444
if not hasattr (resp , 'getheader' ):
428
445
if hasattr (resp .headers , 'getheader' ):
0 commit comments