The Wayback Machine - https://web.archive.org/web/20201127130207/https://github.com/getsentry/raven-python/pull/1260
Skip to content
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

Default usage of raven.Client does not import twisted or requests #1260

Open
wants to merge 6 commits into
base: master
from

Conversation

@skrap
Copy link

@skrap skrap commented Jun 11, 2018

This patch addresses #1258 by taking steps to lazily load the requests and twisted modules.

Summary of changes:

  • Delay the hook_libraries function if the module requested hasn't been loaded yet.
  • Remove and instead lazy load DEFAULT_TRANSPORT (wasn't used outside its .py).
  • Remove the default loading of twisted and requests in their respective transport subclasses. Lazy load what's needed.

Caveats:

  • While I modified existing tests to pass, I was not sure how to write a unit test for this, as performance tests can be tricky.
  • While this should work in all supported pythons, I'm only able to run the tests in latest 2- and 3- series.

Results:
from raven import Client takes 2.3 MB instead of 17 MB RSS.

:/tmp/raven-python# python
Python 2.7.14 (default, Jun  6 2018, 06:11:27) 
[GCC 6.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil 
>>> psutil.Process().memory_info().rss
7794688
>>> from raven import Client
>>> psutil.Process().memory_info().rss
10190848
>>> 
@skrap
Copy link
Author

@skrap skrap commented Jun 12, 2018

Build failures seem unrelated to these changes:
pkg_resources.VersionConflict: (pytest 3.2.5 (/home/travis/build/getsentry/raven-python/.tox/py35-django-200-fix/lib/python3.5/site-packages), Requirement.parse('pytest>=3.6'))

@ashwoods
Copy link
Contributor

@ashwoods ashwoods commented Jun 12, 2018

Yup, almost have a fix ready

@ashwoods
Copy link
Contributor

@ashwoods ashwoods commented Jul 11, 2018

@skrap fixed, then broke again,then fixed again. Mind rebasing from master?

@ashwoods ashwoods self-requested a review Jul 11, 2018
@ashwoods ashwoods self-assigned this Jul 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.