Closed pnbruckner closed 5 years ago
Just thought of another optimization... I know Home Assistant uses this with just one value for retries, so in that case one session will be created and used from then on. But if other users call command with several values for retries over time, especially if they bounce back and forth between a set of values, the session would still get constantly recreated. So, rather than just keeping the latest one around, use a dictionary to save a session per value. This way, once all the various values of retries are used, it will never need to create a new session; it can just switch between the ones that exist. I'll implement that and make another commit soon.
And now that I think about it some more, self._retries_conn and self._timeout_protocol are not thread safe. I'll work on that, too.
This change is ready to go. @tchellomello, can this (and the previous PR) be released in a new version on pypi.org? I'm working on a PR for the amcrest component on HA, and I'd like to have it pull in these changes at the same time.
FYI, I do plan to make one more PR here to add some new commands in support of other enhancements I've made to the HA amcrest component that I will be submitting on other PRs to HA in the near future.
@pnbruckner Thanks for your contribution. I'll publish a new version on pypi.org shortly.
@pnbruckner version 1.2.4
is now published at https://pypi.org/project/amcrest/1.2.4/
Thanks!
In command method, don't create a new requests session every time. Rather, keep a session for each value of retries. Also don't try to update default values for retries and timeout for each command because that wasn't thread safe.