# Buggy code
def yield_execution_pool(self):
    actor_cls = self.get("_actor_cls")
    actor_uid = self.get("_actor_uid")
    op_key = self.get("_op_key")
    if not actor_cls or not actor_uid:  # pragma: no cover
        return

    from .actors import new_client
    from .worker.daemon import WorkerDaemonActor

    client = new_client()

    worker_addr = self.get_local_address()
    if client.has_actor(
        client.actor_ref(WorkerDaemonActor.default_uid(), address=worker_addr)
    ):
        holder = client.actor_ref(WorkerDaemonActor.default_uid(), address=worker_addr)
    else:
        holder = client
    uid = f"w:0:mars-cpu-calc-backup-{os.getpid()}-{op_key}-{random.randint(-1, 9999)}"
    uid = self._actor_ctx.distributor.make_same_process(uid, actor_uid)
    ref = holder.create_actor(actor_cls, uid=uid, address=worker_addr)
    return ref


# Traceback (AssertionError)
Traceback (most recent call last):
File "/Users/wenjun/miniconda3/lib/python3.8/unittest/case.py", line 60, in testPartExecutor
yield
File "/Users/wenjun/miniconda3/lib/python3.8/unittest/case.py", line 676, in run
self._callTestMethod(testMethod)
File "/Users/wenjun/miniconda3/lib/python3.8/unittest/case.py", line 633, in _callTestMethod
method()
File "/Users/wenjun/Code/mars/mars/dataframe/groupby/tests/test_groupby_execution.py", line 401, in testGroupByApply
pd.testing.assert_frame_equal(self.executor.execute_dataframe(applied, concat=True)[0],
File "/Users/wenjun/Code/mars/mars/tests/core.py", line 686, in execute_tileable
result = super().execute_tileable(tileable, *args, **kwargs)
File "/Users/wenjun/Code/mars/mars/utils.py", line 439, in _inner
return func(*args, **kwargs)
File "/Users/wenjun/Code/mars/mars/executor.py", line 720, in execute_tileable
ret = self.execute_graph(chunk_graph, result_keys, n_parallel=n_parallel or n_thread,
File "/Users/wenjun/Code/mars/mars/tests/core.py", line 673, in execute_graph
return super().execute_graph(graph, keys, **kw)
File "/Users/wenjun/Code/mars/mars/executor.py", line 693, in execute_graph
res = graph_execution.execute(retval)
File "/Users/wenjun/Code/mars/mars/executor.py", line 574, in execute
future.result()
File "/Users/wenjun/miniconda3/lib/python3.8/concurrent/futures/_base.py", line 439, in result
return self.__get_result()
File "/Users/wenjun/miniconda3/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
raise self._exception
File "/Users/wenjun/miniconda3/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/Users/wenjun/Code/mars/mars/tests/core.py", line 591, in _execute_operand
super()._execute_operand(op)
File "/Users/wenjun/Code/mars/mars/utils.py", line 439, in _inner
return func(*args, **kwargs)
File "/Users/wenjun/Code/mars/mars/executor.py", line 446, in _execute_operand
self.handle_op(first_op, results, self._mock)
File "/Users/wenjun/Code/mars/mars/executor.py", line 378, in handle_op
return Executor.handle(*args, **kw)
File "/Users/wenjun/Code/mars/mars/executor.py", line 644, in handle
return runner(results, op)
File "/Users/wenjun/Code/mars/mars/dataframe/groupby/apply.py", line 63, in execute
assert len(applied.index) == 1
AssertionError

# Fixed code
def yield_execution_pool(self):
    actor_cls = self.get("_actor_cls")
    actor_uid = self.get("_actor_uid")
    op_key = self.get("_op_key")
    if not actor_cls or not actor_uid:  # pragma: no cover
        return

    from .actors import new_client
    from .actors.errors import ActorAlreadyExist
    from .worker.daemon import WorkerDaemonActor

    client = new_client()

    worker_addr = self.get_local_address()
    if client.has_actor(
        client.actor_ref(WorkerDaemonActor.default_uid(), address=worker_addr)
    ):
        holder = client.actor_ref(WorkerDaemonActor.default_uid(), address=worker_addr)
    else:
        holder = client

    while True:
        try:
            random_tail = "".join(
                random.choice(string.ascii_letters + string.digits) for _ in range(5)
            )
            uid = f"w:0:mars-cpu-calc-backup-{os.getpid()}-{op_key}-{random_tail}"
            uid = self._actor_ctx.distributor.make_same_process(uid, actor_uid)
            ref = holder.create_actor(actor_cls, uid=uid, address=worker_addr)
            break
        except ActorAlreadyExist:  # pragma: no cover
            pass
    return ref