On Mon, Nov 2, 2009 at 4:07 AM, Wim Dumon <[email protected]> wrote: > 2009/11/1 OvermindDL1 <[email protected]>: >> But it still seems to me that if you want to launch another >> application, why does the process creation call block, thus requiring >> you to do odd things like fork or use threads if you want to keep >> things active? Is there not an asynchronous call to create a process >> as is the default in Windows? >> > > The normal way in unix to create a new process is fork() and then one > of the exec() functions. None of them block. System does block, > because it returns the exit value of the application that you execute. > > To come back to the original question: it depends a bit which is the > best approach. In any case, it is generally a good idea to keep the > time spent within a Wt event loop short, for the same reason as it is > not nice to do long computations in any GUI system's event loop: the > GUI locks up for a long time. So what are the alternatives? > - if you're not interested in reporting progress or termination of the > processing: start a new process in the background and forget about it. > - if you want to report progress, realize that this does not work: > void startCalculationSlot() > { > while (!done) { > doSome(); > progressbar->update(...); > } > } > GUI updates are only propagated after you return control to Wt's event > loop. (with a few exceptions) > - You can report progress by using a WTimer. Set the timeout interval > to e.g. 1 second, and query the calculation process to see how far it > is in the slot; report it back to the user. > - You can report progress by using server push. Start a new thread, > which reports progress from time to time using Wt's server push > mechanism (see the simplechat example)
The traditional way I would do such updates is to spawn another thread. But if I am doing something like calling an external app and just waiting for it to return, then I would set an asynchronous event handler to handle the return of the other program and act based on return value or what-not. It still seems rather heavy-weight in any case to fork the process just to wait for an event... And yes, I am using server push, it can be described in a single word, excellent. It is so easy to use compared to an old home-grown solution I had to do the same thing, messing with chunked headers and such annoyances. But yea, if you cannot tell from my programming style, I am heavy on asynchronous programming rather then spawning off new threads/processes and blocking. Might be due to my Erlang usage a while back, it is only and purely asynchronous, rather awesome language, just hate the syntax. ;-) ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ witty-interest mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/witty-interest
