<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def stop_gui_thread():
 """ Try to stop the GUI thread. If it was running returns True, otherwise False. """

    PyGUIThread = getattr(ROOT, 'PyGUIThread', None)

    if PyGUIThread is None or not PyGUIThread.isAlive():
        log.debug("no existing GUI thread is runnng")
        return False

    ROOT.keeppolling = 0
    try:
        PyGUIThread.finishSchedule()
    except AttributeError:
        log.debug("unable to call finishSchedule() on PyGUIThread")
        pass
    PyGUIThread.join()
    log.debug("successfully stopped the existing GUI thread")
    return True