Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions examples/pybullet/gym/pybullet_utils/bullet_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self, connection_mode=None, hostName=None, options=''):
`pybullet.DIRECT` creates a headless simulation,
`pybullet.SHARED_MEMORY` connects to an existing simulation.
"""
self._client = -1
self._shapes = {}
self._pid = os.getpid()
if connection_mode is None:
Expand All @@ -43,11 +44,14 @@ def __del__(self):
except pybullet.error:
pass

def disconnect(self):
"""Disconnect this client and release its id after a successful call."""
pybullet.disconnect(physicsClientId=self._client)
self._client = -1

def __getattr__(self, name):
"""Inject the client id into Bullet functions."""
attribute = getattr(pybullet, name)
if inspect.isbuiltin(attribute):
attribute = functools.partial(attribute, physicsClientId=self._client)
if name=="disconnect":
self._client = -1
return attribute