How to get thread callbacks in Python
This may have been asked before, but I couldn't find what I was looking for. I have a background thread started from the main UI thread (TKinter) and I would like it to send status updates to the UI. I appreciate some code or pseudo or links that show how this can be done in python.
pseudocode: //test.py
def __init__(self, parent):
#Button
self.submit_button = Button(self,
text="launch_tasks",
command=self.launch_tasks).pack()
#label
self.label = Label(master, text="Hello, world!")
self.label.pack()
def launch_tasks(self)
t = Thread(target=self.process_tasks)
t.start()
def process_tasks(self):
cnt = getJobs(self);
self.label = cnt # I like to update label here
for(job in jobs):
process(job)
self.label = 'processing' + job # I like to update label
...
source to share
Tkinter addon with messaging layer with added event routing
While Tkinter / is a standalone Model-Visual-Controller system, you can extend its functionality in a thread-safe, non-blocking mode with an additional (inter-process / any-to-any) native messaging layer added and equip it with local / self-contained members using Tkinter based event routing engine to integrate with .mainloop()
.mainloop()
################################################ SETUP EVENT-ROUTING Injector
self.aSigFromZMQ = "<<aVirtualEventSignalledFromZMQ_LAYER>>"
self.bind( self.aSigFromZMQ, anEventHANDLER )
# |
# .bind <<virtual_EventNAME>> altogether with <anEventHANDLER>-call
################################################ Context-fully TRIGGER Injector
self.event_generate( self.aSigFromZMQ, aSigContextDICT )
# |
# .event_generate( <eventNameId>, **args ) # triggers <eventNameId>
# # + passes **args, that allows
# # to set <keyword>=<value> pairs for Event-fields,
# # that are passed to anEventHANDLER via <Event>-object ...
For illustration and for end-to-end reference to a genuine book from one of the fathers of modern, incredibly fast, smart and scalable inter-process messaging for many-to-many messaging (including cross-thread signaling thereafter) . →> fooobar.com/questions/1561445 / ...
Chaining data (unlimited callbacks)
source to share