ray.util.placement_group.get_current_placement_group() Optional[ray.util.placement_group.PlacementGroup][source]#

Get the current placement group which a task or actor is using.

It returns None if there’s no current placement group for the worker. For example, if you call this method in your driver, it returns None (because drivers never belong to any placement group).


>>> import ray
>>> from ray.util.placement_group import PlacementGroup
>>> from ray.util.placement_group import get_current_placement_group
>>> @ray.remote 
... def f(): 
...     # This will return the placement group the task f belongs to.
...     # It means this pg will be identical to the pg created below.
...     pg = get_current_placement_group() 
>>> pg = PlacementGroup([{"CPU": 2}]) 
>>> f.options(placement_group=pg).remote() 
>>> # New script.
>>> ray.init() 
>>> # New script doesn't belong to any placement group,
>>> # so it returns None.
>>> assert get_current_placement_group() is None 

Placement group object.

None if the current task or actor wasn’t created with any placement group.

Return type


PublicAPI: This API is stable across Ray releases.