Onyx logo

Previous topic

onyx.util.state_machine – Configuration state machine

Next topic

onyx.util.timestamp – Generation of time stamps for general use

This Page

onyx.util.timedict – Simple storage for timing information.

class onyx.util.timedict.TimeDict(*args, **kwds)

Bases: onyx.builtin.ordered_wormattrdict

A simple class for tracking wall and CPU times. A TimeDict holds pairs of times as generated by time.time() and time.clock() in a dictionary with client-provided keys. NB!! - the values returned by clock() may be platform dependent. In particular, MacOSX and Linux may not be using the same scale.

XXX Would be nice if there were a way to access the system value CLOCKS_PER_SEC, but I haven’t found one

>>> td0 = TimeDict()
>>> td0.add_time_mark('a')
>>> sleep_atleast(0.25)
>>> td0.add_time_mark('b')
>>> td0 
TimeDict([('a', TimeDictTuple(wall_time=..., cpu_time=...)), ('b', TimeDictTuple(wall_time=..., cpu_time=...))])
>>> wall_a, cpu_a = td0['a']
>>> wall_b, cpu_b = td0['b']
>>> wall_a + 0.25 <= wall_b
True
>>> cpu_a <= cpu_b
True
>>> wall_a2 = td0['a'].wall_time
>>> wall_a2 is wall_a
True
>>> cpu_a2 = td0['a'].cpu_time
>>> cpu_a2 is cpu_a
True

Initialize an ordered dictionary. Signature is the same as for regular dictionaries, but keyword arguments are not recommended because their insertion order is arbitrary.

add_time_mark(symbol)
clear(*dummy_args)
copy()
classmethod fromkeys(iterable, value=None)

OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S and values equal to v (which defaults to None).

get

D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.

has_key

D.has_key(k) -> True if D has a key k, else False

items()
iteritems()
iterkeys()
itervalues()
keys()
pop(*dummy_args)
popitem(*dummy_args)
setdefault(*dummy_args)
update(*args, **kwds)
values()
viewitems()

od.viewitems() -> a set-like object providing a view on od’s items

viewkeys()

od.viewkeys() -> a set-like object providing a view on od’s keys

viewvalues()

od.viewvalues() -> an object providing a view on od’s values

class onyx.util.timedict.TimeDictTuple

Bases: tuple

TimeDictTuple(wall_time, cpu_time)

count

T.count(value) -> integer – return number of occurrences of value

cpu_time

Alias for field number 1

index

T.index(value, [start, [stop]]) -> integer – return first index of value. Raises ValueError if the value is not present.

wall_time

Alias for field number 0

onyx.util.timedict.sleep_atleast(secs)

Deterministic sleep function. This works around a possible problem with time.sleep(): ‘The actual suspension time may be less than that requested because any caught signal will terminate the sleep() following execution of that signal’s catching routine.’ (from the doc for time.sleep)