Skip to content

Fix monitor thread crash when a phase carries extra_kwargs - #1326

Closed
rootkiller6788 wants to merge 1 commit into
google:masterfrom
rootkiller6788:fix-monitor-extra-kwargs-unpack
Closed

Fix monitor thread crash when a phase carries extra_kwargs#1326
rootkiller6788 wants to merge 1 commit into
google:masterfrom
rootkiller6788:fix-monitor-extra-kwargs-unpack

Conversation

@rootkiller6788

Copy link
Copy Markdown

Problem

openhtf/core/monitors.py _MonitorThread.get_value() filtered the monitored phase's extra_kwargs with:

kwargs = {arg: val for arg, val in self.extra_kwargs if arg in argspec_args}

self.extra_kwargs is a dict (see PhaseDescriptor.extra_kwargs), so iterating it yields its keys. Each key (a string) is then unpacked into arg, val, which raises:

ValueError: too many values to unpack (expected 2)

This happens whenever a phase is parameterized with PhaseDescriptor.with_args(...) (so it carries extra_kwargs) and the monitor function does not take **kwargs. The monitor thread crashes and the test run fails.

Reproduction

import openhtf
from openhtf.core import monitors
from openhtf.core import phase_descriptor

def monitor_func(test):
  return 1

def phase(test, port):
  pass

phase_desc = phase_descriptor.PhaseDescriptor(phase).with_args(port=1234)
monitored = monitors.monitors('meas', monitor_func)(phase_desc)

test = openhtf.Test(monitored)
test.execute(test_start=lambda: 'MyDutId')

Before the fix this logs ValueError: too many values to unpack (expected 2) in meas_MonitorThread and the test FAILs.

Fix

Iterate over self.extra_kwargs.items() instead of the dict itself.

Tests

Added test_get_value_with_extra_kwargs in test/core/monitors_test.py, which exercises a monitor without **kwargs against a phase descriptor carrying extra_kwargs. It fails on master and passes with the fix.

The monitor thread's get_value() iterated over the phase's extra_kwargs
dict directly, yielding keys, and unpacked each key into two names.
When a phase was parameterized with PhaseDescriptor.with_args() and the
monitor function did not accept **kwargs, the monitor thread raised
"ValueError: too many values to unpack (expected 2)" and failed the test.

Iterate over extra_kwargs.items() instead and add a regression test.
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.

1 participant