[#827] Add README text on usage of iRODSSession instances - #832
Conversation
korydraughn
left a comment
There was a problem hiding this comment.
Wording seems good.
Are we encouraging the use of irods.helpers and make_session()?
Are they meant for general usage?
| ```python | ||
| from irods.helpers import make_session | ||
| sess1 = make_session() | ||
|
|
||
| # Possible patterns include: | ||
| # 1. keeping a ready reference to the session. | ||
|
|
||
| sess1.collections.get(f'/tempZone/home/{session.username}') | ||
| # (... Further instances of calls to the server through sess1 may follow.) | ||
|
|
||
| # or: | ||
| # 2. using the session object with a context manager. | ||
|
|
||
| with make_session() as sess2: | ||
| my_user = sess2.users.get(ses.username) | ||
| # Here, we can have other statements using sess2, and at end | ||
| # of code block, sess2.cleanup() is implicitly called. | ||
|
|
||
| # sess1 retains an idle but reusable connection whereas sess2 does not; i.e. | ||
| # sess1.pool.idle has length 1, and sess2.pool.idle is an empty set. | ||
| # However, both sessions are equally open for further server interactions. | ||
| ``` |
There was a problem hiding this comment.
Consider splitting this into two independent code blocks. That should help the reader see the edges of each approach.
| ```python | ||
| from irods.helpers import make_session | ||
| sess1 = make_session() | ||
|
|
||
| # Possible patterns include: | ||
| # 1. keeping a ready reference to the session. | ||
|
|
||
| sess1.collections.get(f'/tempZone/home/{session.username}') | ||
| # (... Further instances of calls to the server through sess1 may follow.) | ||
|
|
||
| # or: | ||
| # 2. using the session object with a context manager. | ||
|
|
||
| with make_session() as sess2: | ||
| my_user = sess2.users.get(ses.username) | ||
| # Here, we can have other statements using sess2, and at end | ||
| # of code block, sess2.cleanup() is implicitly called. | ||
|
|
||
| # sess1 retains an idle but reusable connection whereas sess2 does not; i.e. | ||
| # sess1.pool.idle has length 1, and sess2.pool.idle is an empty set. | ||
| # However, both sessions are equally open for further server interactions. | ||
| ``` |
There was a problem hiding this comment.
I think the comments in the code example should be moved outside of it. They capture the main thing we want to emphasize.
I don't feel we have to encourage it ... if the mention of it as the first option seems like encouraging, perhaps a reorganization is needed. The upshot is: a client environment set up, There is this: |
No description provided.