More pythonic way to manage a list of callbacks
I'm writing a multi-threaded Python application with serial IO, and I have
this construct in the IO class:
def __init__(self):
# Register these with thread-safe functions having the arguments listed
self.callbacks_status = [] # args: (pod_index, message, color)
self.callbacks_conn = [] # args: (pod_index, message, color)
self.callbacks_angle = [] # args: (pod_index, angle_deg)
self.callbacks_brake = [] # args: (brake_on)
Then, when one of my updating threads gets a new status, I'm doing
something like this every time:
for func in self.callbacks_conn:
func(i, "Open", "yellow")
Needless to say, this is ugly and feels non-pythonic. Is there a more
elegant way to call a list of functions with the same arguments? Basically
I am looking for the map function in reverse.
No comments:
Post a Comment