[Gambas-user] gb.task and the event loop?

Tobias Boege taboege at ...626...
Thu Dec 27 11:30:13 CET 2012


On Thu, 27 Dec 2012, Beno?t Minisini wrote:
> Le 23/12/2012 23:08, Tobias Boege a ?crit :
> > Hi Benoit,
> >
> > we have gb.task on our schedule now and I found two examples on the mailing
> > list:
> >
> > - Olivier Cruilles: [0]
> > - Ivan Kern:        [1]
> >
> > Well, the first one seems to be designed to do nothing (no Task-inheriting
> > object is instantiated at all - I don't know if it did work the time it was
> > written, though) but if one modifies it to create a Task, it is almost
> > instantly killed; just as if the Main() was executed and no event loop kicks
> > in, even if a Timer was created which, according to [2], compels the event
> > loop.
> >
> > The second example, mainly listed for completeness, shows a workaround but
> > not a really satisfying one if one would like to do something else than
> > waiting.
> >
> > So, is (or "shall be") gb.task allow operation with the event loop? What's
> > wrong with the first example (the modified one)?
> >
> > Regards,
> > Tobi
> >
> > [0] http://gambas.8142.n7.nabble.com/attachment/24430/0/gbTask-0.0.1.tar.gz
> > [1] http://gambas.8142.n7.nabble.com/attachment/17637/0/TaskTest.zip
> >
> > [2] http://gambasdoc.org/help/cat/eventloop?v3
> >
> 
> Task are actually sub-processes run through the fork() system call. So 
> they can only communicate the main process with the standard 
> input/output streams. The event loop is only run in the main process.
> 

OK.

FYI, the "Application.Daemon = True" hack from Fabien doesn't work. As the
documentation states, this forks again and kills the Task. So the Task
interface for communication is gone and additionally, the program still
exits immediately after Main(). I guess, one cannot have everything :-)

Well, actually one can: Just make your own event-recognising loop

While True
	Wait 1
Wend

at the end of Main().

This works perfectly with a Timer tuned to fire up every 1 second. It's not
optimal but one should be able to start Processess in the background Task,
run Timers, watch Files, etc.

Regards,
Tobi




More information about the User mailing list