<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def start_notebook_on_demand(self, name, context):
 """Start notebook if not yet running with these settings. Return the updated settings with a port info. :return: (context dict, created flag) """

        if self.is_running(name):

            last_context = self.get_context(name)
            logger.info("Notebook context change detected for %s", name)
            if not self.is_same_context(context, last_context):
                self.stop_notebook(name)
                # Make sure we don't get race condition over context.json file
                time.sleep(2.0)
            else:
                return last_context, False

        err_log = os.path.join(self.get_work_folder(name), "notebook.stderr.log")
        logger.info("Launching new Notebook named %s, context is %s", name, context)
        logger.info("Notebook log is %s", err_log)

        self.start_notebook(name, context)
        time.sleep(1)
        context = self.get_context(name)
        if "notebook_name" not in context:
            # Failed to launch within timeout
            raise RuntimeError("Failed to launch IPython Notebook, see {}".format(err_log))

        return context, True