Skip to content

Commit

Permalink
Merge pull request #222 from stdweird/rin_killtasks_graceful
Browse files Browse the repository at this point in the history
vsc.utils.run: improve handling tasks and pgids (HPC-5756)
  • Loading branch information
Jens Timmerman authored Aug 30, 2016
2 parents 2dc7c04 + 07975d3 commit 4e7a895
Show file tree
Hide file tree
Showing 17 changed files with 234 additions and 130 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
setup.cfg

# Packages
.eggs
*.egg
*.egg-info
dist
Expand Down
2 changes: 1 addition & 1 deletion bin/logdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def run(self):
self.logger.handle(logrecord)
except (KeyboardInterrupt, SystemExit):
raise
except:
except Exception:
traceback.print_exc()


Expand Down
39 changes: 14 additions & 25 deletions lib/vsc/utils/affinity.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def convert_hr_bits(self, txt):
for rng in txt.split(','):
indices = [int(x) for x in rng.split('-')] * 2 # always at least 2 elements: twice the same or start,end,start,end

## sanity check
# sanity check
if indices[1] < indices[0]:
self.log.raiseException("convert_hr_bits: end is lower then start in '%s'" % rng)
elif indices[0] < 0:
Expand Down Expand Up @@ -153,7 +153,7 @@ def get_cpus(self):
"""
self.cpus = []
for bitmask in getattr(self, '__bits'):
for idx in xrange(NCPUBITS):
for _ in range(NCPUBITS):
self.cpus.append(bitmask & 1)
bitmask >>= 1
return self.cpus
Expand All @@ -179,12 +179,12 @@ def set_bits(self, cpus=None):
for idx in xrange(NMASKBITS):
cpus = [2 ** cpuidx for cpuidx, val in enumerate(self.cpus[idx * NCPUBITS:(idx + 1) * NCPUBITS]) if val == 1]
__bits[idx] = cpu_mask_t(sum(cpus))
## sanity check
if not prev_cpus == self.get_cpus():
## get_cpus() rescans
self.log.raiseException("set_bits: something went wrong: previous cpus %s; current ones %s" % (prev_cpus[:20], self.cpus[:20]))
else:
# sanity check
if prev_cpus == self.get_cpus():
self.log.debug("set_bits: new set to %s" % self.convert_bits_hr())
else:
# get_cpus() rescans
self.log.raiseException("set_bits: something went wrong: previous cpus %s; current ones %s" % (prev_cpus[:20], self.cpus[:20]))

def str_cpus(self):
"""Return a string representation of the cpus"""
Expand Down Expand Up @@ -234,18 +234,6 @@ def sched_getcpu():
"""Get currently used cpu"""
return _libc.sched_getcpu()

#Utility function
# tobin not used anymore
def tobin(s):
"""Convert integer to binary format"""
## bin() missing in 2.4
# eg: self.cpus.extend([int(x) for x in tobin(bitmask).zfill(NCPUBITS)[::-1]])
if s <= 1:
return str(s)
else:
return tobin(s >> 1) + str(s & 1)


#/* Return the highest priority of any process specified by WHICH and WHO
# (see above); if WHO is zero, the current process, process group, or user
# (as specified by WHO) is used. A lower priority number means higher
Expand All @@ -260,7 +248,7 @@ def getpriority(which=None, who=None):
"""Get the priority"""
if which is None:
which = PRIO_PROCESS
elif not which in (PRIO_PROCESS, PRIO_PGRP, PRIO_USER,):
elif which not in (PRIO_PROCESS, PRIO_PGRP, PRIO_USER,):
_logger.raiseException("getpriority: which %s not in correct range" % which)
if who is None:
who = 0 # current which-ever
Expand All @@ -275,13 +263,14 @@ def setpriority(prio, which=None, who=None):
"""Set the priority (aka nice)"""
if which is None:
which = PRIO_PROCESS
elif not which in (PRIO_PROCESS, PRIO_PGRP, PRIO_USER,):
elif which not in (PRIO_PROCESS, PRIO_PGRP, PRIO_USER,):
_logger.raiseException("setpriority: which %s not in correct range" % which)
if who is None:
who = 0 # current which-ever

try:
prio = int(prio)
except:
except ValueError:
_logger.raiseException("setpriority: failed to convert priority %s into int" % prio)

if prio < PRIO_MIN or prio > PRIO_MAX:
Expand All @@ -298,7 +287,7 @@ def setpriority(prio, which=None, who=None):


if __name__ == '__main__':
## some examples of usage
# some examples of usage
setLogLevelDebug()

cs = cpu_set_t()
Expand All @@ -323,8 +312,8 @@ def setpriority(prio, which=None, who=None):

print sched_getcpu()

## resources
## nice -n 5 python affinity.py prints 5 here
# resources
# nice -n 5 python affinity.py prints 5 here
currentprio = getpriority()
print "getpriority", currentprio
newprio = 10
Expand Down
21 changes: 8 additions & 13 deletions lib/vsc/utils/dateandtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@
import time as _time
from datetime import tzinfo, timedelta, datetime, date

try:
any([0, 1])
except:
from vsc.utils.missing import any


class FancyMonth:
"""Convenience class for month math"""
Expand Down Expand Up @@ -152,7 +147,7 @@ def interval(self, otherdate):
raise(Exception(msg))
else:
nr = self.number(otherdate)
startdate, enddate = self.get_start_end(otherdate)
startdate, _ = self.get_start_end(otherdate)

start = self.__class__(startdate)
all_dates = [start.get_other(m) for m in range(nr)]
Expand Down Expand Up @@ -250,7 +245,7 @@ def datetime_parser(txt):

try:
sects = tmpts[1].split(':')[2].split('.')
except:
except (AttributeError, IndexError):
sects = [0]
# add seconds
datetuple.append(int(sects[0]))
Expand Down Expand Up @@ -280,13 +275,13 @@ def timestamp_parser(timestamp):
class UTC(tzinfo):
"""UTC"""

def utcoffset(self, dt):
def utcoffset(self, dt): # pylint:disable=unused-argument
return ZERO

def tzname(self, dt):
def tzname(self, dt): # pylint:disable=unused-argument
return "UTC"

def dst(self, dt):
def dst(self, dt): # pylint:disable=unused-argument
return ZERO

utc = UTC()
Expand All @@ -303,13 +298,13 @@ def __init__(self, offset, name):
self.__offset = timedelta(minutes=offset)
self.__name = name

def utcoffset(self, dt):
def utcoffset(self, dt): # pylint:disable=unused-argument
return self.__offset

def tzname(self, dt):
def tzname(self, dt): # pylint:disable=unused-argument
return self.__name

def dst(self, dt):
def dst(self, dt): # pylint:disable=unused-argument
return ZERO


Expand Down
1 change: 0 additions & 1 deletion lib/vsc/utils/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def mk_rst_table(titles, columns):
msg = "Number of titles/columns should be equal, found %d titles and %d columns" % (title_cnt, col_cnt)
raise LengthNotEqualException, msg
table = []
col_widths = []
tmpl = []
line= []

Expand Down
6 changes: 3 additions & 3 deletions lib/vsc/utils/fancylogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def log_method(self, msg):
RAISE_EXCEPTION_LOG_METHOD = log_method

# method definition as it is in logging, can't change this
def makeRecord(self, name, level, pathname, lineno, msg, args, excinfo, func=None, extra=None):
def makeRecord(self, name, level, pathname, lineno, msg, args, excinfo, func=None, extra=None): # pylint: disable=unused-argument
"""
overwrite make record to use a fancy record (with more options)
"""
Expand Down Expand Up @@ -243,7 +243,7 @@ def raiseException(self, message, exception=None, catch=False):
self.RAISE_EXCEPTION_LOG_METHOD(fullmessage)
raise exception, message, tb

def deprecated(self, msg, cur_ver, max_ver, depth=2, exception=None, *args, **kwargs):
def deprecated(self, msg, cur_ver, max_ver, depth=2, exception=None, *args, **kwargs): # pylint: disable=unused-argument
"""
Log deprecation message, throw error if current version is passed given threshold.
Expand Down Expand Up @@ -718,7 +718,7 @@ def _enable_disable_default_handlers(enable):

try:
_default_logTo(enable=enable, handler=handler)
except:
except Exception:
pass


Expand Down
Loading

0 comments on commit 4e7a895

Please sign in to comment.