Skip to content

Commit

Permalink
PidIsRunning and HumanReadableSizeString have been moved from mydata/…
Browse files Browse the repository at this point in the history
…models/upload.py to mydata/utils/__init__.py
  • Loading branch information
wettenhj committed Jul 22, 2015
1 parent 161bccb commit 9977c5f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions mydata/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import psutil


def PidIsRunning(pid):
try:
p = psutil.Process(int(pid))
if p.status == psutil.STATUS_DEAD:
return False
if p.status == psutil.STATUS_ZOMBIE:
return False
return True # Assume other status are valid
except psutil.NoSuchProcess:
return False


def HumanReadableSizeString(num):
for x in ['bytes', 'KB', 'MB', 'GB']:
if num < 1024.0 and num > -1024.0:
return "%3.0f %s" % (num, x)
num /= 1024.0
return "%3.0f %s" % (num, 'TB')

0 comments on commit 9977c5f

Please sign in to comment.