Skip to content

Commit

Permalink
Switched from a list of handlers to a single handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark-kun committed Apr 20, 2019
1 parent 2eb2de2 commit 339b2dc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions sdk/python/kfp/dsl/_container_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,8 @@ def _make_hash_based_id_for_container_op(container_op):
return container_op.human_name + ' ' + hex(2**63 + hash(container_op))[2:]


# A stack of functions that can register the ContainerOp instance in some system and generate a unique ID. Only the last handler in the list is used.
_register_container_op_handlers = [_make_hash_based_id_for_container_op]
# Pointer to a function that generates a unique ID for the ContainerOp instance (Possibly by registering the ContainerOp instance in some system).
_register_container_op_handler = _make_hash_based_id_for_container_op


class ContainerOp(object):
Expand Down Expand Up @@ -767,7 +767,7 @@ def _decorated(*args, **kwargs):
# ID of the current ContainerOp. Ideally, it should be generated by the compiler that sees the bigger context.
# However, the ID is used in the task output references (PipelineParams) which can be serialized to strings.
# Because of this we must obtain a unique ID right now.
self.name = _register_container_op_handlers[-1](self)
self.name = _register_container_op_handler(self)

self.outputs = {}
if file_outputs:
Expand Down
5 changes: 3 additions & 2 deletions sdk/python/kfp/dsl/_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,13 @@ def __enter__(self):
def register_op_and_generate_id(op):
return self.add_op(op, op.is_exit_handler)

_container_op._register_container_op_handlers.append(register_op_and_generate_id)
self._old__register_container_op_handler = _container_op._register_container_op_handler
_container_op._register_container_op_handler = register_op_and_generate_id
return self

def __exit__(self, *args):
Pipeline._default_pipeline = None
_container_op._register_container_op_handlers.pop()
_container_op._register_container_op_handler = self._old__register_container_op_handler

def add_op(self, op: _container_op.ContainerOp, define_only: bool):
"""Add a new operator.
Expand Down

0 comments on commit 339b2dc

Please sign in to comment.