kiranvizru / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

Deprecate NUM_CPUS, TOTAL_PHYMEM and BOOT_TIME module constants #451

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Reasons to deprecate them
=========================

- they are calculated at import time, also unnecessarily if the user does not 
use it later

- import time is risky: if the retrieval fails for some reason the whole 
program will explode (see for example  issue 188). Right now we alleviate the 
problem by catching the exception and produce a warning but it's sub optimal.

- BOOT_TIME is already super seeded by psutil.get_boot_time() which reflects 
system clock updates.

- it's rare but total physical memory may change on virtualized systems.

Replacements
============

- NUM_CPUS can be replaced by psutil.cpu_count() (this will also be consistent 
with os.cpu_count() introduced in python 3.4 
http://docs.python.org/3.4/library/os.html#os.cpu_count)

- BOOT_TIME was already being replaced by psutil.get_boot_time() introduced in 
0.7.0

- TOTAL_PHYMEM can be obtained via psutil.virtual_memory().total

Deprecation process
===================

Deprecating a module-level constant is harder than deprecating a function 
because removing it all of the sudden is too disruptive and providing an alias 
which points to the newer function is tricky.
Josiah Carlson provided me a very handy hack which should work though.
I expect to make the transition in some next version (say 1.3.0) which will 
produce a DeprecationWarning and completely remove the constants in a major 
release (say 2.0.0 or 3.0.0).

Original issue reported on code.google.com by g.rodola on 3 Dec 2013 at 9:37

GoogleCodeExporter commented 9 years ago
Issue 450 has been merged into this issue.

Original comment by g.rodola on 3 Dec 2013 at 9:38

GoogleCodeExporter commented 9 years ago
Committed in revision 9895e5862121.
Thanks to Josiah Carlson for having provided the hack to create module 
properties aliasing the functions intended as replacement.

Original comment by g.rodola on 7 Dec 2013 at 4:12

GoogleCodeExporter commented 9 years ago
Closing out as fixed as 2.0.0 version is finally out.

Original comment by g.rodola on 10 Mar 2014 at 11:36