Beispiel #1
0
def quitHandler(engineReference, eventHandler):
    '''quitHandler will be called at the end of the program as well as the
    handler for a pygame.QUIT event. It sound only run once.'''
    if quitHandler.quitting: return
    quitHandler.quitting = True
    menulock.acquire()
    io.tsprint('MAIN: quit handler started.')
    engineReference.stopEngine()
    io.tsprint("MAIN: stopping sound and music...")
    SoundHandler.stopAll()
    SoundHandler.stopMusic()
    io.tsprint("MAIN: done")
    pygame.quit()
    if profiling:
        io.tsprint("MAIN: Stopping profiler and getting data....")
        fout = open(quitHandler.profilingDest, 'a+')
        l = yappi.get_stats(yappi.SORTTYPE_TTOTAL,              
            yappi.SORTORDER_DESCENDING,
            yappi.SHOW_ALL)
        yappi.stop()
        if fout:
            for s in l:
                fout.write(s+'\n')
            fout.close()
            io.tsprint("MAIN: Profiling data written.")
        else:
            io.tserr("MAIN ERROR: Error opening file for profiling data")
    io.tsprint("MAIN: Exiting!")