← Back to team overview

gtg-user team mailing list archive

Re: Unpredictable behaviour from simple script

 

> I'm trying to get my todo lists out of text files and into GTG. Mostly
> I'm still trying to figure out how everything hangs together.
>
> As one step along the way, I thought I'd write a script to dump all of
> the tasks. Here's what I ended up with.
>
> import sys
>
> from GTG.core import CoreConfig
> from GTG.core.datastore import DataStore
>
>
> def get_requester():
>     """Get a `Requester` object that we can use to manipulate the
> store."""
>     config = CoreConfig()
>     data_store = DataStore()
>     for backend in config.get_backends_list():
>         data_store.register_backend(backend)
>     config.save_datastore(data_store)
>     return data_store.get_requester()
>
>
> def main(args):
>     requester = get_requester()
>     for tid in requester.get_tasks_list():
>         print str(requester.get_task(tid))
>         print
>     return 0
>
>
> if __name__ == '__main__':
>     sys.exit(main(sys.argv[1:]))
>
>
> The get_requester bit is cargo-culted from GTG/gtg.py. I don't really
> understand the backend registration, nor the need to call
> save_datastore before I actually do anything.

The early save_datastore is because of a bug that happened in the early
days. Basically, when you open GTG for the first time, the xml file is
created but empty. Unfortunatly, if you don't change anything to the
default tasks and that you close GTG quickly after launching it, the save
method is never called, resulting in an empty xml file. But as empty is
not a valid xml, GTG would crashes at the next launch.

In summary, this save_datastore store the default tasks in your newly
created XML file the first time you launch GTG. It's not useful anymore
afterward (AFAIK) but I don't believe it's really annoying..

>
> Here's what I get when I run the script a few times:
>
> 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?

Looks like buggy threading, will try to understand more what's happening
there.




References