Skip to content

Commit 44186cb

Browse files
committed
Add timeout to RenderServer.render()
This commit adds a configurable timeout to the `render` method signature within `RenderServer`. This defaults to 10 seconds; 5 for sending the request and 5 for reading the response.
1 parent be10f22 commit 44186cb

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

react/render_server.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ def __unicode__(self):
2020

2121

2222
class RenderServer(object):
23-
def render(self, path, props=None, to_static_markup=False, request_headers=None):
23+
def render(
24+
self, path, props=None, to_static_markup=False, request_headers=None,
25+
timeout=None
26+
):
2427
url = conf.settings.RENDER_URL
2528

2629
if props is not None:
@@ -45,12 +48,17 @@ def render(self, path, props=None, to_static_markup=False, request_headers=None)
4548
if request_headers is not None:
4649
all_request_headers.update(request_headers)
4750

51+
# Add a send/receive timeout with the request if not specified
52+
if not isinstance(timeout, (tuple, int, float)):
53+
timeout = (5, 5)
54+
4855
try:
4956
res = requests.post(
5057
url,
5158
data=serialized_options,
5259
headers=all_request_headers,
53-
params={'hash': options_hash}
60+
params={'hash': options_hash},
61+
timeout=timeout
5462
)
5563
except requests.ConnectionError:
5664
raise RenderServerError('Could not connect to render server at {}'.format(url))

0 commit comments

Comments
 (0)