<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def discover_chromecasts(max_devices=None, timeout=DISCOVER_TIMEOUT):
 """ Discover chromecasts on the network. """

    from threading import Event
    browser = False
    try:
        # pylint: disable=unused-argument
        def callback(name):
            """Called when zeroconf has discovered a new chromecast."""
            if max_devices is not None and listener.count >= max_devices:
                discover_complete.set()

        discover_complete = Event()
        listener, browser = start_discovery(callback)

        # Wait for the timeout or the maximum number of devices
        discover_complete.wait(timeout)

        return listener.devices
    except Exception:  # pylint: disable=broad-except
        raise
    finally:
        if browser is not False:
            stop_discovery(browser)