# Buggy code
def run(self, *tensors, **kw):
    from . import tensor as mt

    ret_list = False
    if len(tensors) == 1 and isinstance(tensors[0], (tuple, list)):
        ret_list = True
        tensors = tensors[0]
    elif len(tensors) > 1:
        ret_list = True

    tensors = tuple(mt.tensor(t) for t in tensors)
    result = self._sess.run(*tensors, **kw)
    self._executed_keys.update(t.key for t in tensors)
    for t in tensors:
        t._execute_session = self

    ret = []
    for r, t in zip(result, tensors):
        if r is None:
            ret.append(r)
            continue
        if t.isscalar() and hasattr(r, "item"):
            ret.append(np.asscalar(r))
        else:
            ret.append(r)
    if ret_list:
        return ret
    return ret[0]


# Traceback (mars.actors.errors.ActorAlreadyExist)
Creating operand actors for graph 93ba7372-e748-40ab-af14-6c250f845ba4
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 716, in gevent._greenlet.Greenlet.run
File "mars/actors/pool/gevent_pool.pyx", line 88, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 91, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 102, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/pool/gevent_pool.pyx", line 96, in mars.actors.pool.gevent_pool.ActorExecutionContext.fire_run
File "mars/actors/core.pyx", line 108, in mars.actors.core.FunctionActor.on_receive
File "mars/actors/core.pyx", line 110, in mars.actors.core.FunctionActor.on_receive
File "/Users/hekaisheng/Documents/mars/mars/scheduler/graph.py", line 156, in execute_graph
self.create_operand_actors()
File "/Users/hekaisheng/Documents/mars/mars/scheduler/graph.py", line 569, in create_operand_actors
[future.result() for future in itertools.chain(six.itervalues(op_refs), [write_future])]
File "/Users/hekaisheng/Documents/mars/mars/scheduler/graph.py", line 569, in <listcomp>
[future.result() for future in itertools.chain(six.itervalues(op_refs), [write_future])]
File "src/gevent/event.py", line 457, in gevent._event.AsyncResult.result
File "src/gevent/event.py", line 381, in gevent._event.AsyncResult.get
File "src/gevent/event.py", line 399, in gevent._event.AsyncResult.get
File "src/gevent/event.py", line 379, in gevent._event.AsyncResult._raise_exception
File "/Users/hekaisheng/miniconda3/lib/python3.6/site-packages/gevent/_compat.py", line 47, in reraise
raise value.with_traceback(tb)
File "mars/actors/pool/gevent_pool.pyx", line 758, in mars.actors.pool.gevent_pool.Communicator._create_local_actor
File "mars/actors/pool/gevent_pool.pyx", line 237, in mars.actors.pool.gevent_pool.LocalActorPool.create_actor
mars.actors.errors.ActorAlreadyExist: Actor s:operator$2724de06-fc4a-11e8-8d24-47a7eeef77d5$c84e3ef10df7fabaf2dc028149609284 already exist, cannot create

# Fixed code
def run(self, *tensors, **kw):
    from . import tensor as mt

    ret_list = False
    if len(tensors) == 1 and isinstance(tensors[0], (tuple, list)):
        ret_list = True
        tensors = tensors[0]
    elif len(tensors) > 1:
        ret_list = True

    tensors = tuple(mt.tensor(t) for t in tensors)
    run_tensors = []
    fetch_results = dict()

    # those executed tensors should fetch data directly, submit the others
    for t in tensors:
        if t.key in self._executed_keys:
            fetch_results[t.key] = self.fetch(t)
        else:
            run_tensors.append(t)
    if all([t.key in fetch_results for t in tensors]):
        results = [fetch_results[t.key] for t in tensors]
        return results if ret_list else results[0]

    result = self._sess.run(*run_tensors, **kw)
    self._executed_keys.update(t.key for t in run_tensors)
    for t in run_tensors:
        t._execute_session = self

    ret = []
    for r, t in zip(result, tensors):
        if r is None:
            ret.append(r)
            continue
        if t.isscalar() and hasattr(r, "item"):
            ret.append(np.asscalar(r))
        else:
            ret.append(r)

    results = []
    result_iter = iter(ret)
    for k in [t.key for t in tensors]:
        if k in fetch_results:
            results.append(fetch_results[k])
        else:
            results.append(next(result_iter))
    if ret_list:
        return results
    return results[0]