From: Fredrik Tolf Date: Fri, 27 Sep 2013 05:52:36 +0000 (+0200) Subject: Merge branch 'master' into python3 X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=ebe466f227b464a7457dee55accb1b426821c7c9;hp=9b6845a6a793a189bad2788333663ef4407012e1;p=pdm.git Merge branch 'master' into python3 --- diff --git a/pdm/perf.py b/pdm/perf.py index 6a68676..bad3112 100644 --- a/pdm/perf.py +++ b/pdm/perf.py @@ -45,7 +45,7 @@ It contains two named PERF objects: - platform -- An attribute returning the Python build platform. """ -import os, sys, resource, time, socket, threading +import os, sys, time, socket, threading __all__ = ["attrinfo", "simpleattr", "valueattr", "eventobj", "staticdir", "event", "procevent", "startevent", @@ -232,16 +232,21 @@ class finishevent(procevent): sysres = staticdir() itime = time.time() -ires = resource.getrusage(resource.RUSAGE_SELF) -def ct(): - ru = resource.getrusage(resource.RUSAGE_SELF) - return (ru.ru_utime - ires.ru_utime) + (ru.ru_stime - ires.ru_stime) sysres["realtime"] = simpleattr(func = lambda: time.time() - itime) -sysres["cputime"] = simpleattr(func = ct) -sysres["utime"] = simpleattr(func = lambda: resource.getrusage(resource.RUSAGE_SELF).ru_utime - ires.ru_utime) -sysres["stime"] = simpleattr(func = lambda: resource.getrusage(resource.RUSAGE_SELF).ru_stime - ires.ru_stime) -sysres["maxrss"] = simpleattr(func = lambda: resource.getrusage(resource.RUSAGE_SELF).ru_maxrss) -sysres["rusage"] = simpleattr(func = lambda: resource.getrusage(resource.RUSAGE_SELF)) +try: + import resource +except ImportError: + pass +else: + ires = resource.getrusage(resource.RUSAGE_SELF) + def ct(): + ru = resource.getrusage(resource.RUSAGE_SELF) + return (ru.ru_utime - ires.ru_utime) + (ru.ru_stime - ires.ru_stime) + sysres["cputime"] = simpleattr(func = ct) + sysres["utime"] = simpleattr(func = lambda: resource.getrusage(resource.RUSAGE_SELF).ru_utime - ires.ru_utime) + sysres["stime"] = simpleattr(func = lambda: resource.getrusage(resource.RUSAGE_SELF).ru_stime - ires.ru_stime) + sysres["maxrss"] = simpleattr(func = lambda: resource.getrusage(resource.RUSAGE_SELF).ru_maxrss) + sysres["rusage"] = simpleattr(func = lambda: resource.getrusage(resource.RUSAGE_SELF)) sysinfo = staticdir() sysinfo["pid"] = simpleattr(func = os.getpid)