[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Minor corrections for os.sysconf check



commit df2084b0e746e6c5036528b01884a168b3b513ce
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Wed Mar 28 20:09:08 2012 -0700

    Minor corrections for os.sysconf check
    
    The patch from beckbaibai fixed his issue but left CLOCK_TICKS undefined on
    Windows which would result in a NameError when using proc.get_stats (the
    function *should* cause an error, but not that one).
---
 stem/util/proc.py |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/stem/util/proc.py b/stem/util/proc.py
index 0e9f5ed..e8e253d 100644
--- a/stem/util/proc.py
+++ b/stem/util/proc.py
@@ -33,10 +33,12 @@ import stem.util.log as log
 
 # cached system values
 IS_PROC_AVAILABLE, SYS_START_TIME, SYS_PHYSICAL_MEMORY = None, None, None
-try:
-  CLOCK_TICKS = os.sysconf(os.sysconf_names["SC_CLK_TCK"])
-except AttributeError:
-  pass
+CLOCK_TICKS = None
+
+# os.sysconf is only defined on unix
+try: CLOCK_TICKS = os.sysconf(os.sysconf_names["SC_CLK_TCK"])
+except AttributeError: pass
+
 Stat = stem.util.enum.Enum(("COMMAND", "command"), ("CPU_UTIME", "utime"),
                  ("CPU_STIME", "stime"), ("START_TIME", "start time"))
 
@@ -226,6 +228,9 @@ def get_stats(pid, *stat_types):
     IOError if it can't be determined
   """
   
+  if CLOCK_TICKS == None:
+    raise IOError("Unable to look up SC_CLK_TCK")
+  
   start_time, parameter = time.time(), "process %s" % ", ".join(stat_types)
   
   # the stat file contains a single line, of the form...

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits