raven-python
raven-python copied to clipboard
Default usage of raven.Client does not import twisted or requests
This patch addresses #1258 by taking steps to lazily load the requests and twisted modules.
Summary of changes:
- Delay the
hook_librariesfunction 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
twistedandrequestsin 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
>>>
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'))
Yup, almost have a fix ready
@skrap fixed, then broke again,then fixed again. Mind rebasing from master?