Пример #1
0
def songdbMain():
	# Import modules, which will have the side-effect to
	# init/load the songdb (lazily) and register the GUI.
	import songdb
	import Search

	# This is heavy, ugly, etc...
	# But it's simple nice hack for now to index everything.
	import TaskSystem
	def indexAll():
		import appinfo
		for dir in appinfo.musicdirs:
			TaskSystem.asyncCall(lambda: songdb.indexSearchDir(dir), name="create search index", mustExec=True)
	TaskSystem.daemonThreadCall(indexAll, name="create search index")

	# Reindex played songs.
	from State import state
	from Player import PlayerEventCallbacks
	for ev,args,kwargs in state.updates.read():
		try:
			if ev is PlayerEventCallbacks.onSongChange:
				newSong = kwargs["newSong"]
				songdb.insertSearchEntry(newSong)
		except Exception:
			import sys
			sys.excepthook(*sys.exc_info())
	songdb.flush()
Пример #2
0
def handleApplicationQuit():
    """
	Depending on the environment, this might be called multiple times.
	It should do some cleanup and save the DBs and such.

	Once this get called, the app is not expected to be in a
	functional state anymore.
	
	This is normally registerd via `atexit.register()` in `main()`.
	"""

    import utils
    if utils.quit > 1: return  # Already called before.
    utils.quit = 1

    # first set/send signals to all modules
    from State import modules
    for m in modules:
        m.stop(join=False)
    try:
        # in case there are any subprocesses, interrupt them
        # maybe some modules are hanging and waiting for such
        import sys, os, signal
        os.kill(0, signal.SIGINT)
    except KeyboardInterrupt:
        pass  # well, we expect that...
    except Exception:
        pass

    # now join all
    for m in modules:
        m.stop()

    # Do some cleanup before we let Python do the final cleanup.
    # E.g., it might happen that Python will not GC the player instance
    # soon enough in its `Py_Finalize()`. In that situation, bad things
    # will happen, because most probably, the player instances worker
    # thread is still running in the background. This most probably
    # leads to a crash.
    RootObjs.clear()
    try:
        ctx().rootObjs.clear()
    except Exception:
        pass  # might already be out of scope
    import State
    State.state = None
    import songdb
    songdb.flush()
    import gc
    for _ in range(3):
        gc.collect()

    utils.quit = 2
    print "Bye!"
Пример #3
0
def handleApplicationQuit():
	"""
	Depending on the environment, this might be called multiple times.
	It should do some cleanup and save the DBs and such.

	Once this get called, the app is not expected to be in a
	functional state anymore.
	
	This is normally registerd via `atexit.register()` in `main()`.
	"""

	import utils
	if utils.quit > 1: return # Already called before.
	utils.quit = 1

	# first set/send signals to all modules
	from State import modules
	for m in modules: m.stop(join=False)
	try:
		# in case there are any subprocesses, interrupt them
		# maybe some modules are hanging and waiting for such
		import sys, os, signal
		os.kill(0, signal.SIGINT)
	except KeyboardInterrupt: pass # well, we expect that...
	except Exception: pass

	# now join all
	for m in modules: m.stop()

	# Do some cleanup before we let Python do the final cleanup.
	# E.g., it might happen that Python will not GC the player instance
	# soon enough in its `Py_Finalize()`. In that situation, bad things
	# will happen, because most probably, the player instances worker
	# thread is still running in the background. This most probably
	# leads to a crash.
	RootObjs.clear()
	try: ctx().rootObjs.clear()
	except Exception: pass # might already be out of scope
	import State
	State.state = None
	import songdb
	songdb.flush()
	import gc
	for _ in range(3): gc.collect()

	utils.quit = 2
	print "Bye!"