mirror of
https://github.com/bulletphysics/bullet3.git
synced 2026-09-17 15:54:29 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user