raven-python icon indicating copy to clipboard operation
raven-python copied to clipboard

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

Open skrap opened this issue 7 years ago • 3 comments

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 avatar Jun 11 '18 19:06 skrap

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'))

skrap avatar Jun 12 '18 15:06 skrap

Yup, almost have a fix ready

ashwoods avatar Jun 12 '18 15:06 ashwoods

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

ashwoods avatar Jul 11 '18 16:07 ashwoods