summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
0eaf243)
This makes the module usable on Python implementations, such as
Jython, that lack the resource module.
- platform -- An attribute returning the Python build platform.
"""
- 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",
__all__ = ["attrinfo", "simpleattr", "valueattr", "eventobj",
"staticdir", "event", "procevent", "startevent",
sysres = staticdir()
itime = time.time()
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["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)
sysinfo = staticdir()
sysinfo["pid"] = simpleattr(func = os.getpid)