From 31f851a4486788008f6e2a387ae1a675ca24f029 Mon Sep 17 00:00:00 2001 From: rasbt Date: Sat, 14 May 2016 21:21:52 -0400 Subject: [PATCH] raise `ValueError` if `monitor` is set to `True` and `psutils` is not installed --- CHANGELOG.md | 5 +++++ pyprind/__init__.py | 2 +- pyprind/prog_class.py | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a028290..9f04ccb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +Version 2.9.8 +================ +- raise `ValueError` if `monitor` is set to `True` and `psutils` is not installed + + Version 2.9.7 ================ - requirements.txt for `psutil`, now supports `pip install pyprind -r requirements.txt` diff --git a/pyprind/__init__.py b/pyprind/__init__.py index 7970fcb..08af3c3 100644 --- a/pyprind/__init__.py +++ b/pyprind/__init__.py @@ -17,4 +17,4 @@ from .generator_factory import prog_bar -__version__ = '2.9.7' +__version__ = '2.9.8' diff --git a/pyprind/prog_class.py b/pyprind/prog_class.py index f2a023e..c0ce211 100644 --- a/pyprind/prog_class.py +++ b/pyprind/prog_class.py @@ -16,6 +16,12 @@ import os from io import UnsupportedOperation +try: + import psutil + psutil_import = True +except ImportError: + psutil_import = False + class Prog(): def __init__(self, iterations, track_time, stream, title, @@ -40,9 +46,12 @@ def __init__(self, iterations, track_time, stream, title, self._print_title() self.update_interval = update_interval - if self.monitor: - import psutil - self.process = psutil.Process() + if monitor: + if not psutil_import: + raise ValueError('psutil package is required when using' + ' the `monitor` option.') + else: + self.process = psutil.Process() if self.track: self.eta = 1