Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialize Job Event Params #29

Merged
merged 3 commits into from
Oct 15, 2024

Conversation

wiwichips
Copy link
Collaborator

@wiwichips wiwichips commented Oct 15, 2024

Previously, parameters passed to jon event handler callbacks weren't deserialized. See the example below:

example code:

#!/usr/bin/env python3

import dcp
dcp.init()

from dcp import compute_for

def workfn(datum):
    import dcp
    dcp.progress()

    my_dict = {
        'val': datum + datum
    }

    return my_dict

my_j = compute_for([1], workfn)

my_j.on('result', print)

my_j.public.name = 'simple bifrost2 example'
my_j.computeGroups = [{ 'joinKey': 'will', 'joinSecret': 'bozo' }]

my_j.exec()
res = my_j.wait()

Before this change, the output would be:

{'job': '0xec837b8Dbfc1eBac8A5C7bc51D7fb2Bd19B6286D', 'sliceNumber': 1.0, 'result': <memory at 0x73bb740e0280>}

After this change, the output is now:

{'job': '0x5ECfdb6a856221f070DE657344a5Fe5de8C14e6C', 'sliceNumber': 1.0, 'result': {'val': 2}}

the main diff is that now instead of <memory at 0x73bb740e0280> it prints {'val': 2}

dcp/api/job.py Outdated
nonlocal callback
new_args = []
for arg in inner_args:
if isinstance(arg, dict) and bool(arg):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability, would it be better

Suggested change
if isinstance(arg, dict) and bool(arg):
if isinstance(arg, dict) and len(arg) > 0:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

honestly it's a no-op anyways, not sure why I check the length. It could just be

if isinstance(arg, dict):

I'll change it to that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed in dfe1623

dcp/api/job.py Outdated
# deserialize job on event parameters before passing them to user defined callback
def cb_deserialize_wrapper(callback):
def new_cb(*inner_args):
nonlocal callback
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to change callback? If not, it's probably better to remove this line.

Suggested change
nonlocal callback

dcp/api/job.py Show resolved Hide resolved
@wiwichips wiwichips merged commit 9d5cb70 into main Oct 15, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants