-
-
Notifications
You must be signed in to change notification settings - Fork 394
api: Use requests.Session #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
zulip/zulip/__init__.py
Outdated
@@ -327,6 +351,8 @@ def do_api_query(self, orig_request, url, method="POST", longpolling=False, file | |||
for f in files: | |||
req_files.append((f.name, f)) | |||
|
|||
self._init_session() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe self.ensure_session()
would be a better name here?
The code looks good; posted one quick comment. Some thoughts on your notes:
|
Thanks for the feedback. I'm traveling this weekend, but I'll try to deal early next week.
…On July 20, 2017 4:07:54 PM PDT, Tim Abbott ***@***.***> wrote:
The code looks good; posted one quick comment. Some thoughts on your
notes:
* I think threadsafety is something I'd rather handle via
locking/whatever if we find a use for it.
* For typeshed, I'd open an issue in Typeshed and use `# type: ignore #
link to issue` to silence the warnings in our code and reference it so
it's clear why and when we can clean it up. We'll be type-checking the
API again eventually.
* Correct, this has no real test suite in this project yet (there's a
bit more of one in the server project in the form of `tools/test-api`
there). Might be worth running that against this project, because I
think there's a good chance that its mocking strategy won't work with
this.
--
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#18 (comment)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
Cool |
@dehnert quick ping on this :) |
Using requests.Session allows the requests library to reuse HTTP connections, which is potentially helpful for performance. This fixes python-zulip-api #3.
I fixed these comments last night, except that I haven't been able to run |
@eeshangarg do you have time to quickly run |
Passed in Travis ! (I Tried porting a subset of the backend test in zulip/zulip |
@rht for the zulip/zulip issue, you just need to update |
Merged, thanks @dehnert! I think it'll be easier to test by hand once it's merged and we can just include it in the server repo. It seems pretty unlikely that it'll fail in a nontrivial way. |
Thanks folks! |
As of commit 5eaac7b (zulip#18), zulip.Client is not thread-safe and especially not fork-safe due to connections held open by requests.Session. Delay construction of the Client until after forking off zulip_to_zephyr. Replace the fork for each message sent by zephyr_to_zulip with a threaded queue worker. Signed-off-by: Anders Kaseorg <[email protected]>
As of commit 5eaac7b (zulip#18), zulip.Client is not thread-safe and especially not fork-safe due to connections held open by requests.Session. Delay construction of the Client until after forking off zulip_to_zephyr. Replace the fork for each message sent by zephyr_to_zulip with a threaded queue worker. Signed-off-by: Anders Kaseorg <[email protected]>
As of commit 5eaac7b (#18), zulip.Client is not thread-safe and especially not fork-safe due to connections held open by requests.Session. Delay construction of the Client until after forking off zulip_to_zephyr. Replace the fork for each message sent by zephyr_to_zulip with a threaded queue worker. Signed-off-by: Anders Kaseorg <[email protected]>
Using requests.Session allows the requests library to reuse HTTP connections,
which is potentially helpful for performance. This fixes python-zulip-api #3.
Some notes:
mypy
(though not the version that Zulip has pinned). Beyond some warnings about stubs that I think are preexisting, I get some errors about request.Session's field typing. I think typeshed is just wrong; Stubs for requests are too restrictive python/typeshed#1093 certainly does not leave me with much faith in the stubs. Comparing Session's stubs to .request's stubs the former is certainly more restrictive, and I don't believe the stubs' typing for verify (which really does seem to take a string) or auth (which does seem to take an object -- though in fairness it looks like passing a (user,pass) tuple should work too, and the stubs support it). I'm not sure what to do about this, especially given that the API seems annotated but not currently being tested.I think this is sane to merge, although you might reasonably want me to change how I handled these notes (or have other objections).