Project

General

Profile

When is it appropriate to call Wt::Application::processEvents() ?

Added by Zach Motsinger almost 8 years ago

I have noticed that sometimes my application will not update when I make certain changes to pages and/or widgets. For example, I often see situations similar to what is described in this thread: http://redmine.emweb.be/boards/2/topics/7638

Because of this, I have gotten in the habit of using processEvents() somewhat liberally whenever I encounter an issue like this. However, lately I have noticed my application will occasionally crash during these calls. The specific error I see is this:

[2016-Jun-24 09:08:46.420157] 31394 [/ L0r8zvyYLdoQ2Piz] [error] "Wt: error during event handling"
[2016-Jun-24 09:08:46.420306] 31394 [/ L0r8zvyYLdoQ2Piz] [error] "Wt: fatal error: caught unknown exception."
[2016-Jun-24 09:08:46.421001] 31394 [/ L0r8zvyYLdoQ2Piz] [info] "Wt: session destroyed (#sessions = 0)"

Of course, if I comment out the call to processEvents(), the session does not crash, but the widget also does not update.

I am wondering what causes these crashes to happen, and if there is a way I can circumvent this problem. Also, I guess I am curious as to why I should have to call processEvents() at all; is there a way I can restructure my pages in order to eliminate this need? Also, I suppose I still am wondering if there is a safe way to make this call.

Any insight would be greatly appreciated.

Thank you!


Replies (2)

RE: When is it appropriate to call Wt::Application::processEvents() ? - Added by Stefan Arndt almost 8 years ago

Hi,

#1 There might be a missunderstanding in how Wt works. You will not get any UI changes until the main event loop is complete with it's run. In this forum thread you linked to, the author calls a function which will make some heavy processing. Say this is a reaction to a button press. The user clicks a button and the event will be send to the server. Wt will then process the event and call the long running function. At the end(!), the change in UI state is send back to the client. Changes are not send immediately, but only once the event-call returns (Wt is complete with procesing). So in this function you can call widget~~hide() and show() as often as you want~~ all that matters is the last state it is in and you do NOT get any intermediate shows/hides.

You can however implement such things like a progress bar using some functions of Wt::WApplication. Search for "Manipulation outside the main event loop" in the docs: https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WApplication.html

#2 The error you posted above indicates an uncatched exception. If it is one of your own exceptions, you may also have further problems.

If this does not solve your problem, could you please provide an example of what code exactly does not work as expected?

RE: When is it appropriate to call Wt::Application::processEvents() ? - Added by Stefan Arndt almost 8 years ago

Ok, I should have taken a look at processEvents() before writing anything, sorry. I don't know why you encounter such issues, but I think blocking the main event loop (by calling processEvents) feels ugly and should be avoided. I use a lot of async stuff and never had the need to use processEvents(). Can you use the methods such as "WApplication::triggerUpdate()"? If not, what are your use cases where you have to use processEvents()?

Is there any chance to take a look at your application?

    (1-2/2)