×

Discussion Board

Results 1 to 6 of 6

Thread: Next problem...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    16

    Smile Next problem...

    Hi all,
    this time I think I have a somewhat general problem, not S60 specific. But as people are so nice around here, I'll get on your nerves with this too...

    I wonder why this little script here crashes everytime I exit it by any means:

    Code:
    #!/usr/bin/python
    #Import a set of VCards in a file into the contacts database of a Series 60 Phone, esp. from Kontact (KDE)
    
    import re, contacts, codecs, graphics, e32, appuifw
    
    expremptyline = re.compile(r"\r\n\r\n", re.IGNORECASE & re.MULTILINE)
    exprswitchtel = re.compile(r"TEL\;TYPE=", re.IGNORECASE & re.MULTILINE)
    
    def exportforseries60(vcard):
     return exprswitchtel.sub(r"TEL;", vcard)
    
    def readfile(filename):
     file = codecs.open(filename,"r","utf8")  
     inhalt = file.read()
     file.close()
     return inhalt
    
    def writetext(s,clear = True,x = 0, y = 12):
     if clear: draw.clear()
     draw.text((x,y),s,0x008000)
    
    def carryon(event):
     global lockjc
     lockjc.signal()
    
    def quit():
     global lockjc
     lockjc.signal() #so it won't be locked in any case
     appuifw.app.exit_key_handler=None #don't know if this is necessary
     appuifw.app.set_exit()
     
    appuifw.app.title=u"Import VCards"
    canvas=appuifw.Canvas(event_callback=carryon)
    appuifw.app.body=canvas
    draw=graphics.Draw(canvas)
    
    lockjc=e32.Ao_lock()
    appuifw.app.exit_key_handler=quit
    
    vcardstrings = expremptyline.split(readfile(r"e:\python\addressbook.vcf")) #last line is an empty newline (ist Kontact schuld)
    writetext(u"%s VCards aus Datei geöffnet"%(len(vcardstrings)-1))
    
    contactdb = contacts.open()
    allenamen = contactdb.keys()
    laengeallenamen = len(allenamen)
    writetext(u"Es sind %s Kontakte im Telefonbuch vorhanden."%(laengeallenamen),False,0,24)
    lockjc.wait()
    for i in range(laengeallenamen):
     writetext(u"Lösche Kontakt Nr.: %s/%s"%(i+1, laengeallenamen))
     e32.ao_yield()
     del contactdb[allenamen[i]] #Missing here is the compact method to get the db-file small again (see other post of mine)
    
    appuifw.note(u"Alle %s Kontakte gelöscht..."%(laengeallenamen),"info")
    
    laengevcardstring = len(vcardstrings)
    for g in range(laengevcardstring):
     writetext(u"Importiere VCard Nr.: %s/%s"%(g, laengevcardstring-1))
     contactdb.import_vcards(exportforseries60(vcardstrings[g]))
     e32.ao_yield()
    
    allenamen = contactdb.keys()
    laengeallenamen = len(allenamen)
    contactdb.close()
    appuifw.note(u"%s Kontakte importiert!"%(laengeallenamen),"info")
    So, if anyone can enlighten me, please do! I have this (probably same) problem with some other scripts, too, and would like to get rid of it.

    Thanks & bye,

    Joost

  2. #2
    Super Contributor
    Join Date
    Dec 2004
    Posts
    643
    The main problem in your script is that you exit from it during a .wait() on an e32.Ao_lock. Unfortunately it would be quite hard to make sure that exiting the interpreter in such situations would work properly. You should make sure that all .wait()s have completed before exiting your app.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    16
    Hi,

    yes, I already read that this would cause problems. But I thought I would release every possible lock in my quit()-method by doing:

    Code:
    def quit():
     global lockjc
     lockjc.signal() #so it won't be locked in any case
     appuifw.app.exit_key_handler=None #don't know if this is necessary
     appuifw.app.set_exit()
    I can't see how the lock could still be in wait when the script reaches app.set_exit()?
    I'm still investigating other crashes also in scripts where I don't use e32 at all, and suspect a problem with the canvas stuff. Is there any need to reset this to something special while exiting an application?

    Thanks & bye,

    Joost

  4. #4
    Regular Contributor
    Join Date
    Dec 2004
    Location
    Czech Republic
    Posts
    50
    Originally posted by sx1freak
    Hi,

    yes, I already read that this would cause problems. But I thought I would release every possible lock in my quit()-method by doing:

    Code:
    def quit():
     global lockjc
     lockjc.signal() #so it won't be locked in any case
     appuifw.app.exit_key_handler=None #don't know if this is necessary
     appuifw.app.set_exit()
    I can't see how the lock could still be in wait when the script reaches app.set_exit()?
    I'm still investigating other crashes also in scripts where I don't use e32 at all, and suspect a problem with the canvas stuff. Is there any need to reset this to something special while exiting an application?

    Thanks & bye,

    Joost
    try calling set_exit() only when app isn't running standalone (either installed in menu or run by appmgr). If it's running under Python interpreter, it should be enough to release the lock. So try this:

    Code:
    if appuifw.app.full_name()[-10:] != 'Python.app':
        appuifw.app.set_exit()

  5. #5
    Super Contributor
    Join Date
    Dec 2004
    Posts
    643
    Originally posted by sx1freak
    Hi,

    yes, I already read that this would cause problems. But I thought I would release every possible lock in my quit()-method by doing:

    Code:
    def quit():
     global lockjc
     lockjc.signal() #so it won't be locked in any case
     appuifw.app.exit_key_handler=None #don't know if this is necessary
     appuifw.app.set_exit()
    I can't see how the lock could still be in wait when the script reaches app.set_exit()?
    When you call .wait() it will start an event processing loop (known as an "Active Scheduler" in Symbian-speak) that runs until the lock is .signal()ed. If a UI event occurs during this time, the UI callback code is executed. If you .signal() the lock from within the UI callback, the event processing loop is marked as "to be finished", but it won't actually be finished until you return from the UI callback back into the loop.

    Yes, this can be a bit confusing.

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    16
    Ok, thanks!
    I think I'm going to get around this now! But first I'm off to check the new release (1.1.5) and see if the database compact methods are in! ;-)

    Thanks again,

    Joost

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •