Skip to content

Commit

Permalink
[State] Add pid to the actor table data. (ray-project#22434)
Browse files Browse the repository at this point in the history
It is requested by users that they'd like to get the pid of actors using ray.state.actors. This PR addresses that.
  • Loading branch information
rkooo567 authored Feb 17, 2022
1 parent 740def0 commit 4ecb2af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions python/ray/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def _gen_actor_info(self, actor_table_data):
"StartTime": actor_table_data.start_time,
"EndTime": actor_table_data.end_time,
"DeathCause": actor_table_data.death_cause,
"Pid": actor_table_data.pid,
}
return actor_info

Expand Down
16 changes: 9 additions & 7 deletions python/ray/tests/test_global_state.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pytest

try:
Expand Down Expand Up @@ -92,30 +93,31 @@ def test_global_state_actor_table(ray_start_regular):
@ray.remote
class Actor:
def ready(self):
pass
return os.getpid()

# actor table should be empty at first
assert len(ray.state.actors()) == 0

# actor table should contain only one entry
def get_actor_table_data(field):
return list(ray.state.actors().values())[0][field]

a = Actor.remote()
ray.get(a.ready.remote())
pid = ray.get(a.ready.remote())
assert len(ray.state.actors()) == 1
assert get_actor_table_data("Pid") == pid

# actor table should contain only this entry
# even when the actor goes out of scope
del a

def get_state():
return list(ray.state.actors().values())[0]["State"]

dead_state = convert_actor_state(gcs_utils.ActorTableData.DEAD)
for _ in range(10):
if get_state() == dead_state:
if get_actor_table_data("State") == dead_state:
break
else:
time.sleep(0.5)
assert get_state() == dead_state
assert get_actor_table_data("State") == dead_state


def test_global_state_worker_table(ray_start_regular):
Expand Down

0 comments on commit 4ecb2af

Please sign in to comment.