Skip to content

Commit

Permalink
fix linux test
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-x-c committed Sep 2, 2024
1 parent 3194420 commit 2e5db8d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/sphinx_doc/en/source/tutorial/208-distribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ This process has a potential issue: the original agent is initialized twice, onc
```

```{note}
Some IDEs might display a hint indicating that the `to_dist` parameter does not exist, but this will not cause an error at runtime.
Some IDEs might display a hint indicating that the `to_dist` parameter does not exist, but this will not cause an error at runtime.
Additionally, if the `to_dist` parameter has already been passed in the initialization parameters, the `to_dist` method should not be called again.
```

Expand Down
5 changes: 5 additions & 0 deletions src/agentscope/_init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
"""The init function for the package."""
import json
import multiprocessing
from typing import Optional, Union, Sequence
from agentscope import agents
from .agents import AgentBase
Expand Down Expand Up @@ -76,6 +77,10 @@ def init(
studio_url (`Optional[str]`, defaults to `None`):
The url of the agentscope studio.
"""
# set the multiprocessing start method
start_method = multiprocessing.get_start_method()
if start_method != "spawn":
multiprocessing.set_start_method("spawn", force=True)
# Init the runtime
ASManager.get_instance().initialize(
model_configs=model_configs,
Expand Down
9 changes: 7 additions & 2 deletions src/agentscope/rpc/rpc_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from .rpc_agent_client import RpcAgentClient, call_func_in_thread
from .rpc_async import AsyncResult
from ..exception import AgentCreationError
from ..exception import AgentCreationError, AgentServerNotAliveError


def get_public_methods(cls: type) -> list[str]:
Expand Down Expand Up @@ -97,9 +97,12 @@ def __init__(
studio_url=studio_url, # type: ignore[arg-type]
)
self._launch_server()
self.client = RpcAgentClient(self.host, self.port)
else:
self.client = RpcAgentClient(self.host, self.port)
if not connect_existing:
self.create(configs)
if launch_server:
self._check_created()
else:
self._creating_stub = None

Expand Down Expand Up @@ -136,6 +139,8 @@ def _launch_server(self) -> None:
host=self.host,
port=self.port,
)
if not self.client.is_alive():
raise AgentServerNotAliveError(self.host, self.port)

def stop(self) -> None:
"""Stop the RpcAgent and the rpc server."""
Expand Down
2 changes: 1 addition & 1 deletion src/agentscope/server/servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def _process_task(
args = None
agent = self.get_agent(agent_id)
if isinstance(args, AsyncResult):
args._fetch_result() # pylint: disable=W0212
args = args.result() # pylint: disable=W0212
try:
if target_func == "reply":
result = getattr(agent, target_func)(args)
Expand Down

0 comments on commit 2e5db8d

Please sign in to comment.