# Buggy code
def start_execution(self, session_id, graph_key, send_addresses=None, callback=None):
    """
    Submit graph to the worker and control the execution
    :param session_id: session id
    :param graph_key: key of the execution graph
    :param send_addresses: targets to send results after execution
    :param callback: promise callback
    """
    graph_record = self._graph_records[(session_id, graph_key)]
    if send_addresses:
        graph_record.send_addresses = send_addresses

    # add callbacks to callback store
    if callback is None:
        callback = []
    elif not isinstance(callback, list):
        callback = [callback]
    graph_record.finish_callbacks.extend(callback)
    try:
        del self._result_cache[(session_id, graph_key)]
    except KeyError:
        pass

    @log_unhandled
    def _wait_free_slot(*_):
        return self._dispatch_ref.get_free_slot("cpu", _promise=True)

    @log_unhandled
    def _handle_success(*_):
        self._notify_successors(session_id, graph_key)
        self._invoke_finish_callbacks(session_id, graph_key)

    @log_unhandled
    def _handle_rejection(*exc):
        # some error occurred...
        logger.debug("Entering _handle_rejection() for graph %s", graph_key)
        self._dump_execution_states()

        if graph_record.stop_requested:
            graph_record.stop_requested = False
            if not isinstance(exc[1], ExecutionInterrupted):
                exc = build_exc_info(ExecutionInterrupted)

        if isinstance(exc[1], ExecutionInterrupted):
            logger.warning("Execution of graph %s interrupted.", graph_key)
        else:
            logger.exception(
                "Unexpected error occurred in executing graph %s",
                graph_key,
                exc_info=exc,
            )

        self._result_cache[(session_id, graph_key)] = GraphResultRecord(
            *exc, **dict(succeeded=False)
        )
        self._invoke_finish_callbacks(session_id, graph_key)

    # collect target data already computed
    save_sizes = dict()
    for target_key in graph_record.data_targets:
        if self._chunk_store.contains(session_id, target_key):
            save_sizes[target_key] = self._chunk_store.get_actual_size(
                session_id, target_key
            )
        elif spill_exists(target_key):
            save_sizes[target_key] = get_spill_data_size(target_key)

    # when all target data are computed, report success directly
    if all(k in save_sizes for k in graph_record.data_targets):
        logger.debug(
            "All predecessors of graph %s already computed, call finish directly.",
            graph_key,
        )
        self._result_cache[(session_id, graph_key)] = GraphResultRecord(save_sizes)
        _handle_success()
    else:
        promise.finished().then(
            lambda: self._prepare_graph_inputs(session_id, graph_key)
        ).then(_wait_free_slot).then(
            lambda uid: self._send_calc_request(session_id, graph_key, uid)
        ).then(
            lambda uid, sizes: self._dump_cache(session_id, graph_key, uid, sizes)
        ).then(_handle_success, _handle_rejection)


# Traceback (ValueError)
500 GET /worker?endpoint
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/tornado/web.py", line 1592, in _execute
result = yield result
File "/opt/conda/lib/python3.6/site-packages/tornado/gen.py", line 1133, in run
value = future.result()
File "/opt/conda/lib/python3.6/site-packages/tornado/gen.py", line 1147, in run
yielded = self.gen.send(value)
File "/opt/conda/lib/python3.6/site-packages/bokeh/server/views/doc_handler.py", line 27, in get
template_variables=session.document.template_variables)
File "/opt/conda/lib/python3.6/site-packages/bokeh/embed/server.py", line 230, in server_html_page_for_session
template=template, template_variables=template_variables)
File "/opt/conda/lib/python3.6/site-packages/bokeh/embed/elements.py", line 133, in html_page_for_render_items
html = template.render(context)
File "/opt/conda/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "/opt/conda/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/opt/conda/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/opt/conda/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/worker_detail.html", line 1, in top-level template code
{% extends "base.html" %}
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/base.html", line 65, in top-level template code
{% block body %}{% endblock %}
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/templates/worker_detail.html", line 252, in block "body"
<td>{{ stats['min_est_finish_time'] | format_ts }}</td>
File "/home/admin/work/public-mars-0.2.0b1-cupid.zip/mars/web/server.py", line 49, in format_ts
return datetime.fromtimestamp(value).strftime('%Y-%m-%d %H:%M:%S')
ValueError: Invalid value NaN (not a number)
500 GET /worker?endpoint=10.101.216.148:53630 (10.101.202.142) 137.45ms

# Fixed code
def start_execution(self, session_id, graph_key, send_addresses=None, callback=None):
    """
    Submit graph to the worker and control the execution
    :param session_id: session id
    :param graph_key: key of the execution graph
    :param send_addresses: targets to send results after execution
    :param callback: promise callback
    """
    graph_record = self._graph_records[(session_id, graph_key)]
    if send_addresses:
        graph_record.send_addresses = send_addresses

    # add callbacks to callback store
    if callback is None:
        callback = []
    elif not isinstance(callback, list):
        callback = [callback]
    graph_record.finish_callbacks.extend(callback)
    try:
        del self._result_cache[(session_id, graph_key)]
    except KeyError:
        pass

    @log_unhandled
    def _wait_free_slot(*_):
        return self._dispatch_ref.get_free_slot("cpu", _promise=True)

    @log_unhandled
    def _handle_success(*_):
        self._invoke_finish_callbacks(session_id, graph_key)

    @log_unhandled
    def _handle_rejection(*exc):
        # some error occurred...
        logger.debug("Entering _handle_rejection() for graph %s", graph_key)
        self._dump_execution_states()

        if graph_record.stop_requested:
            graph_record.stop_requested = False
            if not isinstance(exc[1], ExecutionInterrupted):
                exc = build_exc_info(ExecutionInterrupted)

        if isinstance(exc[1], ExecutionInterrupted):
            logger.warning("Execution of graph %s interrupted.", graph_key)
        else:
            logger.exception(
                "Unexpected error occurred in executing graph %s",
                graph_key,
                exc_info=exc,
            )

        self._result_cache[(session_id, graph_key)] = GraphResultRecord(
            *exc, **dict(succeeded=False)
        )
        self._invoke_finish_callbacks(session_id, graph_key)

    # collect target data already computed
    save_sizes = dict()
    for target_key in graph_record.data_targets:
        if self._chunk_store.contains(session_id, target_key):
            save_sizes[target_key] = self._chunk_store.get_actual_size(
                session_id, target_key
            )
        elif spill_exists(target_key):
            save_sizes[target_key] = get_spill_data_size(target_key)

    # when all target data are computed, report success directly
    if all(k in save_sizes for k in graph_record.data_targets):
        logger.debug(
            "All predecessors of graph %s already computed, call finish directly.",
            graph_key,
        )
        self._result_cache[(session_id, graph_key)] = GraphResultRecord(save_sizes)
        _handle_success()
    else:
        promise.finished().then(
            lambda: self._prepare_graph_inputs(session_id, graph_key)
        ).then(_wait_free_slot).then(
            lambda uid: self._send_calc_request(session_id, graph_key, uid)
        ).then(
            lambda uid, sizes: self._dump_cache(session_id, graph_key, uid, sizes)
        ).then(_handle_success, _handle_rejection)