<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def wait_for_server(host, port, cancel_event=None):
 """ Blocks until a local server is listening on the specified host and port. Set cancel_event to cancel the wait. This is intended to be used in conjunction with running the Flask server. """

    while not is_server_running(host, port):
        # Stop waiting if shutting down
        if cancel_event and cancel_event.is_set():
            return False
        time.sleep(0.1)
    return True