← Back to team overview

gtg-user team mailing list archive

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.

Here's what I get when I run the script a few times:

jml@truth:~/src/gtg$ python import-from-text.py
Task Object
Title:  Brainstorm ideas for TDD talk
Id:     2@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x1643d40>]

Task Object
Title:  Advanced TDD talk
Id:     0@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x164d878>]

Task Object
Title:  Response from OSDC committee
Id:     1@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x164af38>]

jml@truth:~/src/gtg$ python import-from-text.py
Task Object
Title:  Brainstorm ideas for TDD talk
Id:     2@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x240afc8>]

Task Object
Title:  Response from OSDC committee
Id:     1@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x2410fc8>]

Exception in thread Thread-7 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "/usr/lib/python2.6/threading.py", line 525, in __bootstrap_inner
  File "/usr/lib/python2.6/threading.py", line 477, in run
  File "/usr/lib/pymodules/python2.6/GTG/core/datastore.py", line 244,
in __write
  File "/usr/lib/pymodules/python2.6/GTG/backends/localfile.py", line
116, in set_task
  File "/usr/lib/python2.6/xml/dom/minidom.py", line 45, in toxml
  File "/usr/lib/python2.6/xml/dom/minidom.py", line 59, in toprettyxml
  File "/usr/lib/python2.6/xml/dom/minidom.py", line 812, in writexml
  File "/usr/lib/python2.6/xml/dom/minidom.py", line 527, in __getitem__
<type 'exceptions.TypeError'>: 'NoneType' object is not callable
Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:
jml@truth:~/src/gtg$ python import-from-text.py
Task Object
Title:  Brainstorm ideas for TDD talk
Id:     2@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x2893fc8>]

Task Object
Title:  Advanced TDD talk
Id:     0@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x289c7e8>]

Task Object
Title:  Response from OSDC committee
Id:     1@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x2899fc8>]

jml@truth:~/src/gtg$ python import-from-text.py
Task Object
Title:  Brainstorm ideas for TDD talk
Id:     2@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x2989fc8>]

Task Object
Title:  Advanced TDD talk
Id:     0@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x29927e8>]

Task Object
Title:  Response from OSDC committee
Id:     1@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x298ffc8>]

jml@truth:~/src/gtg$ python import-from-text.py
Task Object
Title:  Brainstorm ideas for TDD talk
Id:     2@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x1e0afc8>]

Task Object
Title:  Advanced TDD talk
Id:     0@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x1e137e8>]

Task Object
Title:  Response from OSDC committee
Id:     1@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x1e10fc8>]

jml@truth:~/src/gtg$ python import-from-text.py
Task Object
Title:  Brainstorm ideas for TDD talk
Id:     2@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x2df8fc8>]

Task Object
Title:  Advanced TDD talk
Id:     0@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x2e017e8>]

Task Object
Title:  Response from OSDC committee
Id:     1@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x2dfefc8>]

jml@truth:~/src/gtg$ python import-from-text.py
Task Object
Title:  Brainstorm ideas for TDD talk
Id:     2@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x255bfc8>]

Task Object
Title:  Advanced TDD talk
Id:     0@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x25647e8>]

Task Object
Title:  Response from OSDC committee
Id:     1@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x2561fc8>]

jml@truth:~/src/gtg$ python import-from-text.py
Task Object
Title:  Brainstorm ideas for TDD talk
Id:     2@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x1558fc8>]

Task Object
Title:  Response from OSDC committee
Id:     1@1
Status: Active
Tags:   [<GTG.core.tagstore.Tag instance at 0x155efc8>]



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?

Thanks,
jml



Follow ups