Merge pull request #3819 from cadop/bullet-client-subprocess-safety

Fix for bullet_client to be used from a class instance during multiprocessing
This commit is contained in:
erwincoumans
2021-05-12 13:54:00 -07:00
committed by GitHub

View File

@@ -1,6 +1,7 @@
"""A wrapper for pybullet to manage different clients."""
from __future__ import absolute_import
from __future__ import division
import os
import functools
import inspect
import pybullet
@@ -21,6 +22,7 @@ class BulletClient(object):
`pybullet.SHARED_MEMORY` connects to an existing simulation.
"""
self._shapes = {}
self._pid = os.getpid()
if connection_mode is None:
self._client = pybullet.connect(pybullet.SHARED_MEMORY, options=options)
if self._client >= 0:
@@ -34,7 +36,7 @@ class BulletClient(object):
def __del__(self):
"""Clean up connection if not already done."""
if self._client>=0:
if self._client>=0 and self._pid == os.getpid():
try:
pybullet.disconnect(physicsClientId=self._client)
self._client = -1