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

Cannot use variable binding in message handlers #5781

Open
nils-werner opened this issue Apr 26, 2022 · 0 comments
Open

Cannot use variable binding in message handlers #5781

nils-werner opened this issue Apr 26, 2022 · 0 comments

Comments

@nils-werner
Copy link

nils-werner commented Apr 26, 2022

What happened?

I am trying to write a Python block with a variable number of message inputs. Of course I don't want to implement a fixed number of message handlers for a variable number of ports, so I would write one handler and assign all ports to it, with another parameter port indicating which port was used:

class example(gr.basic_block):
    def __init__(
        self,
        receivers=1,
    ):
        super().__init__(
            name="Example",
            in_sig=None,
            out_sig=None,
        )

        for i in range(receivers):
            self.message_port_register_in(pmt.intern(f"receiver{i}"))
            self.set_msg_handler(pmt.intern(f"receiver{i}"), functools.partialmethod(self.receiver_handler, port=i))

    def receiver_handler(self, message, port=0):
        print(port, message)

and

id: message_example
label: Multi Message Example

templates:
  make: >
      example(
        receivers=${receivers},
      )

parameters:
-   id: receivers
    label: Receivers
    dtype: int
    default: '2'
    hide: 'part'

inputs:
-   domain: message
    label: receiver
    optional: true
    multiplicity: ${ receivers }

file_format: 1

However this is not possible because internally GNURadio is keeping a string reference to my method, instead of a pointer:

I believe a more portable solution would be to store method pointers instead of strings here.

System Information

OS: Arch Linux
GR Installation Method: Conda

GNU Radio Version

3.10 (maint-3.10)

Specific Version

3.10.1.1

Steps to Reproduce the Problem

  1. Create block from above
  2. Connect message inputs to some message source
  3. Generate and run graph

Relevant log output

  File "example.py", line 93, in __init__
    self.set_msg_handler(pmt.intern(f"receiver{i}"), functools.partialmethod(self.receiver_handler, i))
  File "/lib/python3.10/site-packages/gnuradio/gr/gateway.py", line 228, in set_msg_handler
    which_port, handler_function.__name__)
AttributeError: 'partialmethod' object has no attribute '__name__'. Did you mean: '__ne__'?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants