Skip to content

Message handlers are no longer cleared#589

Open
alxbilger wants to merge 1 commit intosofa-framework:masterfrom
alxbilger:dontclear
Open

Message handlers are no longer cleared#589
alxbilger wants to merge 1 commit intosofa-framework:masterfrom
alxbilger:dontclear

Conversation

@alxbilger
Copy link
Contributor

Currently, the following code is not working as expected:

with MessageHandler() as msg_handler:
    SofaRuntime.init()
    # emit a message so it is captured by msg_handler

This is because SofaRuntime.init() removes all the messages handlers, including msg_handler. The consequence is that the emitted messages are not captured by msg_handler.

Instead of removing all the message handlers, I suggest to remove only MainConsoleMessageHandler.

If it's necessary to remove all the message handlers, a binding has been introduced in #588.

@damienmarchal
Copy link
Contributor

You are right the presented code does not work.

Because the dispatcher is a singleton of Sofa, the SofaRuntime.init() is supposed to be called before MessageHandler()... because SofaRuntime is actually the API that manipulates the singleons.

To fix this I would be more in favore or designing the API so it is clear that MessageHandler is actually doing something on the "runtime" singletons. Maybe moving the MessageHandler into SofaRuntime... .

@alxbilger
Copy link
Contributor Author

the SofaRuntime.init() is supposed to be called before MessageHandler()

I agree but I am in this situation because of unit testing of Python scripts. The Python script calls SofaRuntime.ini() (or not, it's up to the script developer), and I insert a message handler before calling the script.

I am not satisfied by this PR so far. It needs more thinking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants