towhee.dag.utils.callstack.Callstack

class towhee.dag.utils.callstack.Callstack(ignore: int = 0)[source]

Bases: object

A Callstack object contains the working frames at the moment.

Parameters:

ignore (int) – The number of frames to ignore on the top of the callstack.

Methods

find_func

Given a function name, find the first-matched and outermost frame from current stack.

hash

Get the hash value of the attributes contained in items between index start and end (includes start, excludes end).

num_frames

Get the number of frames.

__init__(ignore: int = 0)[source]
find_func(func_name: str) Optional[int][source]

Given a function name, find the first-matched and outermost frame from current stack.

Parameters:

func_name (str) – The function name to find.

Returns:

(Union[int, None])

If at least one matching frame exits, return the first-matched frame index. Else, return None.

hash(start: Optional[int] = None, end: Optional[int] = None, items: Optional[List[str]] = None) str[source]

Get the hash value of the attributes contained in items between index start and end (includes start, excludes end).

Parameters:
  • start (int) – The index of the start frame.

  • end (int) – The index of the end frame.

  • items (List[str]) – The items to be hashed. Supported items are {filename, lineno, function, code_context, position, lasti}, where code_context denotes the current line of code of the context, position denotes the frame’s index of the callstack, lasti denotes the index of last attempted instruction in bytecode.

Returns:

(str)

The hash value.

Raises:
  • (IndexError) – If the args [start, end) is out of the frame range or end less than start.

  • (ValueError) – If an item in items is not supported, i.e. not one of {filename, lineno, function, code_context, position, lasti}.

num_frames() int[source]

Get the number of frames.

Returns:

(int)

The size of current stack.