Asked this question on stackoverflow, will synchronize with this thread for users who only use groups.
https://stackoverflow.com/questions/48762163/why-does-wx-yield-not-workI am well aware/familiar how to handle [LongRunningTasks](
https://wiki.wxpython.org/LongRunningTasks) in wxPython (using ``threading.Thread`` is just working fine). But I always wondered, why ``wx.Yield()`` and its siblings are not working (or how they shall be used properly).
Attached a (not so) minimal example, tested with ``4.0.0a2 msw (phoenix)``:
from __future__ import print_function
from time import sleep
from datetime import datetime
import wx
def long_running(handler):
for i in range(10):
thetxt = '{0}: {1}'.format(str(datetime.now()), str(i))
sleep(1) # using this as drop-in for something which is blocking
wx.SafeYield()
wx.CallAfter(handler, thetxt)
class tst_frm(wx.Frame):
def __init__(self, *args, **kwds):
wx.Frame.__init__(self, *args, **kwds)
self.btn = wx.Button(self, -1, 'Click to Status')
self.btn.Bind(wx.EVT_BUTTON, self.on_btn)
def on_btn(self, evt):
the_txt = '{0}: EVT_BUTTON'.format(str(datetime.now()))
self.update_prog(the_txt)
def update_prog(self, update_txt):
"""Handler for task update (``str``)."""
print(update_txt)
if __name__ == '__main__':
app = wx.App(redirect=False)
frm = tst_frm(None, -1, 'test_long')
frm.Show()
handler = frm
long_running(handler.update_prog)
app.MainLoop()
The button clicks are being registered, but neither the ``wx.CallAfter`` events nor the button events are being processed until after ``long_running`` has completed.
My questions:
* ``wx.Yield`` should allow to process events which are piling up?
* Can this example being made work with ``wx.Yield`` and if yes, how?
* If not, What is the explanation why it does not work?