Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
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 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

Yup, almost have a fix ready

@ashwoods
Copy link
Contributor

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

@ashwoods ashwoods self-requested a review July 11, 2018 16:29
@ashwoods ashwoods self-assigned this Jul 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants