Commit a41b332cda6631e4fde498e4e0589d100b73d0f5
1 parent
1aaf2ccb
Exists in
master
and in
5 other branches
FIX: compatibility with older psutil versions
Showing
1 changed file
with
16 additions
and
9 deletions
Show diff stats
invesalius/utils.py
... | ... | @@ -224,15 +224,22 @@ def calculate_resizing_tofitmemory(x_size,y_size,n_slices,byte): |
224 | 224 | |
225 | 225 | # USING PSUTIL |
226 | 226 | import psutil |
227 | - if (psutil.version_info<(0,6,0)): | |
228 | - ram_free = psutil.phymem_usage().free + psutil.cached_phymem() + psutil.phymem_buffers() | |
229 | - ram_total = psutil.phymem_usage().total | |
230 | - swap_free = psutil.virtmem_usage().free | |
231 | - else: | |
232 | - ram_free = psutil.virtual_memory().available | |
233 | - ram_total = psutil.virtual_memory().total | |
234 | - swap_free = psutil.swap_memory().free | |
235 | - | |
227 | + | |
228 | + try: | |
229 | + if (psutil.version_info>=(0,6,0)): | |
230 | + ram_free = psutil.virtual_memory().available | |
231 | + ram_total = psutil.virtual_memory().total | |
232 | + swap_free = psutil.swap_memory().free | |
233 | + else: | |
234 | + ram_free = psutil.phymem_usage().free + psutil.cached_phymem() + psutil.phymem_buffers() | |
235 | + ram_total = psutil.phymem_usage().total | |
236 | + swap_free = psutil.virtmem_usage().free | |
237 | + except: | |
238 | + print "Exception! psutil version < 0.3 (not recommended)" | |
239 | + ram_total = psutil.TOTAL_PHYMEM # this is for psutil < 0.3 | |
240 | + ram_free = 0.8 * psutil.TOTAL_PHYMEM | |
241 | + swap_free = psutil.avail_virtmem() | |
242 | + | |
236 | 243 | print "RAM_FREE=", ram_free |
237 | 244 | print "RAM_TOTAL=", ram_total |
238 | 245 | ... | ... |