Skip to content

Commit 25548b1

Browse files
committed
add option to the Render class to create a new session by default
1 parent 67aaf25 commit 25548b1

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

renderapi/render.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,25 @@ class Render(object):
3232
render client scripts path to which make_kwargs will default
3333
session : requests.sessions.Session
3434
session object to which make_kwargs will default
35+
create_session : bool
36+
create a new session for this instance of render if no session was
37+
provided, allowing the same session to be reused for requests and
38+
increasing performance, defaults to True
3539
3640
"""
3741

3842
def __init__(self, host=None, port=None, owner=None, project=None,
39-
client_scripts=None, session=None, **kwargs):
43+
client_scripts=None, session=None, create_session=True,
44+
**kwargs):
4045
self.DEFAULT_HOST = host
4146
self.DEFAULT_PORT = port
4247
self.DEFAULT_PROJECT = project
4348
self.DEFAULT_OWNER = owner
4449
self.DEFAULT_CLIENT_SCRIPTS = client_scripts
45-
self.session = session
50+
if create_session and session is None:
51+
self.session = requests.Session()
52+
else:
53+
self.session = session
4654

4755
logger.debug('Render object created with '
4856
'host={h}, port={p}, project={pr}, '
@@ -155,6 +163,10 @@ class RenderClient(Render):
155163
render client scripts path to which make_kwargs will default
156164
session : requests.sessions.Session
157165
session object to which make_kwargs will default
166+
create_session : bool
167+
create a new session for this instance of render if no session was
168+
provided, allowing the same session to be reused for requests and
169+
increasing performance, defaults to True
158170
client_script : str
159171
location of wrapper script for java client with input same as Render
160172
java client's run_ws_client.sh

0 commit comments

Comments
 (0)