Skip to content

Conversation

@ckbaumann
Copy link
Contributor

@ckbaumann ckbaumann commented Oct 6, 2020

This PR allows to observe monkey patched methods (you replace or modify method attributes of a class instance s.t. methods are called that were not in the original class definition).

Additionally, the error when trying to add private methods as observers was made a little more explicit.

@papr
Copy link
Contributor

papr commented Oct 8, 2020

@ckbaumann Starting the Head Pose Tracker in Capture using the --debug arg results in this traceback:

Traceback (most recent call last):
  File "/Users/papr/work/pupil/pupil_src/launchables/world.py", line 648, in world
    g_pool.plugins = Plugin_List(g_pool, loaded_plugins)
  File "/Users/papr/work/pupil/pupil_src/shared_modules/plugin.py", line 383, in __init__
    self.add(plugin, args)
  File "/Users/papr/work/pupil/pupil_src/shared_modules/plugin.py", line 398, in add
    plugin_instance = new_plugin_cls(self.g_pool, **args)
  File "/Users/papr/work/pupil/pupil_src/shared_modules/head_pose_tracker/online_head_pose_tracker.py", line 53, in __init__
    self._setup_renderers()
  File "/Users/papr/work/pupil/pupil_src/shared_modules/head_pose_tracker/online_head_pose_tracker.py", line 76, in _setup_renderers
    self._detection_renderer = plugin_ui.DetectionRenderer(
  File "/Users/papr/work/pupil/pupil_src/shared_modules/head_pose_tracker/ui/detection_renderer.py", line 41, in __init__
    plugin.add_observer("gl_display", self._on_gl_display)
  File "/Users/papr/work/pupil/pupil_src/shared_modules/observable.py", line 75, in add_observer
    add_observer(self, method_name, observer)
  File "/Users/papr/work/pupil/pupil_src/shared_modules/observable.py", line 135, in add_observer
    _install_protection_descriptor_if_not_exists(wrapper)
  File "/Users/papr/work/pupil/pupil_src/shared_modules/observable.py", line 172, in _install_protection_descriptor_if_not_exists
    wrapped_method = wrapper.get_wrapped_bound_method()
  File "/Users/papr/work/pupil/pupil_src/shared_modules/observable.py", line 297, in get_wrapped_bound_method
    return self._wrapped_method_ref.deref_method()
  File "/Users/papr/work/pupil/pupil_src/shared_modules/observable.py", line 421, in deref_method
    raise _ReferenceNoLongerValidError
observable._ReferenceNoLongerValidError

@papr
Copy link
Contributor

papr commented Oct 8, 2020

@ckbaumann For reference, this is how we patch the gl_display method.

Copy link
Contributor

@papr papr left a comment

Choose a reason for hiding this comment

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

@ckbaumann Works as expected now! Thanks for working on the fix!

@ckbaumann ckbaumann force-pushed the observe_monkey_patched_methods branch from bbc4c8b to 7c8b8fe Compare October 12, 2020 12:46
@ckbaumann
Copy link
Contributor Author

ckbaumann commented Oct 12, 2020

Rebased onto current develop.
@papr The line you applied black to was modified in the last commits, so I removed the "apply black" commit to keep history shorter
@papr needs review starting with 61604d3

@ckbaumann ckbaumann force-pushed the observe_monkey_patched_methods branch from 7c8b8fe to 7e74cf3 Compare October 12, 2020 13:04
@ckbaumann ckbaumann requested a review from papr October 13, 2020 08:43
@papr papr merged commit f24b6a8 into pupil-labs:develop Oct 13, 2020
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