Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Make psutil optional #992

Merged
merged 1 commit into from Aug 8, 2016

Conversation

Projects
None yet
2 participants
Owner

erikjohnston commented Aug 8, 2016

No description provided.

@NegativeMjark NegativeMjark commented on the diff Aug 8, 2016

synapse/metrics/__init__.py
@@ -68,9 +68,18 @@ def register_cache(self, *args, **kwargs):
def register_memory_metrics(hs):
- metric = MemoryUsageMetric(hs)
+ try:
+ import psutil
+ process = psutil.Process()
+ process.memory_info().rss
+ except (ImportError, AttributeError):
+ logger.warn(
+ "psutil is not installed or incorrect version."
+ " Disabling memory metrics."
+ )
+ return
@NegativeMjark

NegativeMjark Aug 8, 2016

Contributor

Maybe move the rest of the function inside the try block rather than returning here?

@erikjohnston

erikjohnston Aug 8, 2016

Owner

I prefer to keep try...except as narrow as possible, to ensure we don't accidentally consume legitimate errors.

@NegativeMjark

NegativeMjark Aug 8, 2016

Contributor

Fair enough

Contributor

NegativeMjark commented Aug 8, 2016

LGTM

@erikjohnston erikjohnston merged commit e7674eb into develop Aug 8, 2016

9 of 10 checks passed

Sytest Dendron (Merged PR) Build started sha1 is merged.
Details
Flake8 + Packaging (Commit) Build #1388 origin/erikj/psutil_conditional succeeded in 41 sec
Details
Flake8 + Packaging (Merged PR) Build finished.
Details
Sytest Dendron (Commit) Build #485 origin/erikj/psutil_conditional succeeded in 8 min 54 sec
Details
Sytest Postgres (Commit) Build #1319 origin/erikj/psutil_conditional succeeded in 6 min 32 sec
Details
Sytest Postgres (Merged PR) Build finished.
Details
Sytest SQLite (Commit) Build #1353 origin/erikj/psutil_conditional succeeded in 5 min 13 sec
Details
Sytest SQLite (Merged PR) Build finished.
Details
Unit Tests (Commit) Build #1424 origin/erikj/psutil_conditional succeeded in 2 min 43 sec
Details
Unit Tests (Merged PR) Build finished.
Details

@richvdh richvdh deleted the erikj/psutil_conditional branch Dec 1, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment