You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to use an event-based workflow with a Signal class, that provides following mechanisms:
connect/disconnect: registers / unregisters python functions and c++-functions as callbacks
emit: calls all registered callbacks with passed arguments
Problem:
the callbacks are stored as std::function in a std::list
in order to unregister a callback or to avoid registering the same callback twice, a comparison operator for std::function is required
the proposed implementation for Signal class and comparison operator works for c++ callbacks, but doesnt for python callbacks:
test with cpp callback (works!)
fromsignalimportSignal, cpp_callbacks=Signal()
s.connect(cpp_callback)
s.emit()
s.connect(cpp_callback) # <- throws an exception as already connected
test with python callback (fails!)
fromsignalimportSignaldefpy_callback1():
print("py_callback1 called")
defpy_callback2():
print("py_callback2 called")
s=Signal()
s.connect(py_callback1)
s.connect(py_callback2) # <- throws an exception, because the cast to target function (std::function::target()) does not work
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Goal:
I would like to use an event-based workflow with a Signal class, that provides following mechanisms:
Problem:
test with cpp callback (works!)
test with python callback (fails!)
signal.cpp
Beta Was this translation helpful? Give feedback.
All reactions