@@ -120,7 +120,7 @@ def convert_hr_bits(self, txt):
120120 for rng in txt .split (',' ):
121121 indices = [int (x ) for x in rng .split ('-' )] * 2 # always at least 2 elements: twice the same or start,end,start,end
122122
123- ## sanity check
123+ # sanity check
124124 if indices [1 ] < indices [0 ]:
125125 self .log .raiseException ("convert_hr_bits: end is lower then start in '%s'" % rng )
126126 elif indices [0 ] < 0 :
@@ -153,7 +153,7 @@ def get_cpus(self):
153153 """
154154 self .cpus = []
155155 for bitmask in getattr (self , '__bits' ):
156- for idx in xrange (NCPUBITS ):
156+ for _ in range (NCPUBITS ):
157157 self .cpus .append (bitmask & 1 )
158158 bitmask >>= 1
159159 return self .cpus
@@ -179,12 +179,12 @@ def set_bits(self, cpus=None):
179179 for idx in xrange (NMASKBITS ):
180180 cpus = [2 ** cpuidx for cpuidx , val in enumerate (self .cpus [idx * NCPUBITS :(idx + 1 ) * NCPUBITS ]) if val == 1 ]
181181 __bits [idx ] = cpu_mask_t (sum (cpus ))
182- ## sanity check
183- if not prev_cpus == self .get_cpus ():
184- ## get_cpus() rescans
185- self .log .raiseException ("set_bits: something went wrong: previous cpus %s; current ones %s" % (prev_cpus [:20 ], self .cpus [:20 ]))
186- else :
182+ # sanity check
183+ if prev_cpus == self .get_cpus ():
187184 self .log .debug ("set_bits: new set to %s" % self .convert_bits_hr ())
185+ else :
186+ # get_cpus() rescans
187+ self .log .raiseException ("set_bits: something went wrong: previous cpus %s; current ones %s" % (prev_cpus [:20 ], self .cpus [:20 ]))
188188
189189 def str_cpus (self ):
190190 """Return a string representation of the cpus"""
@@ -234,18 +234,6 @@ def sched_getcpu():
234234 """Get currently used cpu"""
235235 return _libc .sched_getcpu ()
236236
237- #Utility function
238- # tobin not used anymore
239- def tobin (s ):
240- """Convert integer to binary format"""
241- ## bin() missing in 2.4
242- # eg: self.cpus.extend([int(x) for x in tobin(bitmask).zfill(NCPUBITS)[::-1]])
243- if s <= 1 :
244- return str (s )
245- else :
246- return tobin (s >> 1 ) + str (s & 1 )
247-
248-
249237#/* Return the highest priority of any process specified by WHICH and WHO
250238# (see above); if WHO is zero, the current process, process group, or user
251239# (as specified by WHO) is used. A lower priority number means higher
@@ -260,7 +248,7 @@ def getpriority(which=None, who=None):
260248 """Get the priority"""
261249 if which is None :
262250 which = PRIO_PROCESS
263- elif not which in (PRIO_PROCESS , PRIO_PGRP , PRIO_USER ,):
251+ elif which not in (PRIO_PROCESS , PRIO_PGRP , PRIO_USER ,):
264252 _logger .raiseException ("getpriority: which %s not in correct range" % which )
265253 if who is None :
266254 who = 0 # current which-ever
@@ -275,13 +263,14 @@ def setpriority(prio, which=None, who=None):
275263 """Set the priority (aka nice)"""
276264 if which is None :
277265 which = PRIO_PROCESS
278- elif not which in (PRIO_PROCESS , PRIO_PGRP , PRIO_USER ,):
266+ elif which not in (PRIO_PROCESS , PRIO_PGRP , PRIO_USER ,):
279267 _logger .raiseException ("setpriority: which %s not in correct range" % which )
280268 if who is None :
281269 who = 0 # current which-ever
270+
282271 try :
283272 prio = int (prio )
284- except :
273+ except ValueError :
285274 _logger .raiseException ("setpriority: failed to convert priority %s into int" % prio )
286275
287276 if prio < PRIO_MIN or prio > PRIO_MAX :
@@ -298,7 +287,7 @@ def setpriority(prio, which=None, who=None):
298287
299288
300289if __name__ == '__main__' :
301- ## some examples of usage
290+ # some examples of usage
302291 setLogLevelDebug ()
303292
304293 cs = cpu_set_t ()
@@ -323,8 +312,8 @@ def setpriority(prio, which=None, who=None):
323312
324313 print sched_getcpu ()
325314
326- ## resources
327- ## nice -n 5 python affinity.py prints 5 here
315+ # resources
316+ # nice -n 5 python affinity.py prints 5 here
328317 currentprio = getpriority ()
329318 print "getpriority" , currentprio
330319 newprio = 10
0 commit comments