← Back to team overview

gtg-user team mailing list archive

Re: Unpredictable behaviour from simple script

 

On Thu, Jul 23, 2009 at 1:42 AM, Lionel Dricot<ploum@xxxxxxxxx> wrote:
>
>> Sometimes I get 2 tasks, sometimes 3, sometimes I get an exception.
>> What's the deal? Am I using the API incorrectly, or is there some
>> buggy threading interaction going on?
>
> I have the answer.
>
> If you add a time.sleep(1) after the get_requester line, everything will
> be fine.
>
> The reason for that is the following : the requester is started in its own
> thread beacause it can take time to build it.
>
> You can see that in the GTK interface with a very long task list : tasks
> will be added progressively to the interface during the first second.
>
> So what is happening right now is that the requester has still not read
> the whole XML file.
>

This makes some degree of sense. However, I feel very strongly that
this level of threading decision should be made by the GUI layer. It
has no bearing on, say, import scripts.

> The problem I see is that the "every task is loaded" has no sense with
> some backend. A connected backend, for example, could only say : those
> were the task at time XX (but maybe tasks were added since that).
>
> This is not a problem for the taskbrowser because we use the requester
> asynchronously. So any suggestion on how to improve this situation is
> welcome.
>

My suggestions, briefly, are:
  * to distinguish between 'push' and 'pull' backends
  * to make the requester more event-driven. i.e. give it methods like
'got_task' that take a task as a parameter
  * only use threads at the top level of the code, if at all.

jml



Follow ups

References