# Buggy code
def start(self, event=None, block=False):
    self._configure_loop()
    self._try_start_web_server()

    if not block:
        self._server_thread = threading.Thread(target=self._server.io_loop.start)
        self._server_thread.daemon = True
        self._server_thread.start()

        if event:
            event.set()
    else:
        if event:
            event.set()

        self._server.io_loop.start()


# Traceback (KeyError)
In [1]: import mars.remote as mr

In [2]: from mars.deploy.local import new_cluster

In [3]: c = new_cluster()
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0604 14:30:01.529353 132840896 store.cc:1149] Allowing the Plasma store to use up to 3.43597GB of memory.
I0604 14:30:01.534931 132840896 store.cc:1176] Starting object store with directory /tmp and huge page support disabled

In [4]: def f(x):
...:     return
...:

In [5]: mr.spawn(f, 3).execute()
Unhandled exception in promise
Traceback (most recent call last):
File "/Users/qinxuye/Workspace/mars/mars/worker/storage/client.py", line 299, in copy_to
return promise.finished(*build_exc_info(KeyError, err_msg), _accept=False)
KeyError: 'Data key (6f8edc26-0267-44a0-a64d-e939bac89fbe, d9f9097c4ccb8ca4716366cf6680fff2) not exist, proc_id=9'
Unhandled exception in promise
Traceback (most recent call last):
File "/Users/qinxuye/Workspace/mars/mars/worker/storage/client.py", line 299, in copy_to
return promise.finished(*build_exc_info(KeyError, err_msg), _accept=False)
KeyError: 'Data key (6f8edc26-0267-44a0-a64d-e939bac89fbe, d9f9097c4ccb8ca4716366cf6680fff2) not exist, proc_id=9'
Unexpected error occurred in executing graph e0879bcab1971118787b182578bff091
Traceback (most recent call last):
File "/Users/qinxuye/Workspace/mars/mars/worker/storage/client.py", line 299, in copy_to
return promise.finished(*build_exc_info(KeyError, err_msg), _accept=False)
KeyError: 'Data key (6f8edc26-0267-44a0-a64d-e939bac89fbe, d9f9097c4ccb8ca4716366cf6680fff2) not exist, proc_id=9'
Attempt 1: Unexpected error KeyError occurred in executing operand e0879bcab1971118787b182578bff091 in 0.0.0.0:37928
Traceback (most recent call last):
File "/Users/qinxuye/Workspace/mars/mars/worker/storage/client.py", line 299, in copy_to
return promise.finished(*build_exc_info(KeyError, err_msg), _accept=False)
KeyError: 'Data key (6f8edc26-0267-44a0-a64d-e939bac89fbe, d9f9097c4ccb8ca4716366cf6680fff2) not exist, proc_id=9'
Unhandled exception in promise
Traceback (most recent call last):
File "/Users/qinxuye/Workspace/mars/mars/worker/storage/client.py", line 299, in copy_to
return promise.finished(*build_exc_info(KeyError, err_msg), _accept=False)
KeyError: 'Data key (6f8edc26-0267-44a0-a64d-e939bac89fbe, d9f9097c4ccb8ca4716366cf6680fff2) not exist, proc_id=9'
Unhandled exception in promise
Traceback (most recent call last):
File "/Users/qinxuye/Workspace/mars/mars/worker/storage/client.py", line 299, in copy_to
return promise.finished(*build_exc_info(KeyError, err_msg), _accept=False)
KeyError: 'Data key (6f8edc26-0267-44a0-a64d-e939bac89fbe, d9f9097c4ccb8ca4716366cf6680fff2) not exist, proc_id=9'
Unexpected error occurred in executing graph e0879bcab1971118787b182578bff091
Traceback (most recent call last):
File "/Users/qinxuye/Workspace/mars/mars/worker/storage/client.py", line 299, in copy_to
return promise.finished(*build_exc_info(KeyError, err_msg), _accept=False)
KeyError: 'Data key (6f8edc26-0267-44a0-a64d-e939bac89fbe, d9f9097c4ccb8ca4716366cf6680fff2) not exist, proc_id=9'
Attempt 2: Unexpected error KeyError occurred in executing operand e0879bcab1971118787b182578bff091 in 0.0.0.0:37928
Traceback (most recent call last):
File "/Users/qinxuye/Workspace/mars/mars/worker/storage/client.py", line 299, in copy_to
return promise.finished(*build_exc_info(KeyError, err_msg), _accept=False)
KeyError: 'Data key (6f8edc26-0267-44a0-a64d-e939bac89fbe, d9f9097c4ccb8ca4716366cf6680fff2) not exist, proc_id=9'

# Fixed code
def start(self, event=None, block=False):
    self._configure_loop()
    self._try_start_web_server()

    if not block:
        self._server_thread = threading.Thread(target=self._server.io_loop.start)
        self._server_thread.daemon = True
        self._server_thread.start()

        if event:
            event.set()
    else:
        if event:
            event.set()

        try:
            self._server.io_loop.start()
        except KeyboardInterrupt:
            pass