Not connected to physics server when trying to run environment

Official Python bindings with a focus on reinforcement learning and robotics.
Post Reply
jboyml
Posts: 1
Joined: Mon Jul 22, 2019 8:49 pm

Not connected to physics server when trying to run environment

Post by jboyml » Mon Jul 22, 2019 8:52 pm

Hi,

I'm trying to use PyBullet for reinforcement learning and can't get started with a simple example. The code below fails with the following error:
Traceback (most recent call last):
File "test.py", line 10, in <module>
observation, reward, done, info = env.step(action)
File "/home/john/anaconda3/lib/python3.6/site-packages/gym/wrappers/time_limit.py", line 15, in step
observation, reward, done, info = self.env.step(action)
File "/home/john/anaconda3/lib/python3.6/site-packages/pybullet_envs/gym_pendulum_envs.py", line 31, in step
self.robot.apply_action(a)
File "/home/john/anaconda3/lib/python3.6/site-packages/pybullet_envs/robot_pendula.py", line 25, in apply_action
self.slider.set_motor_torque(100 * float(np.clip(a[0], -1, +1)))
File "/home/john/anaconda3/lib/python3.6/site-packages/pybullet_envs/robot_bases.py", line 381, in set_motor_torque
self.set_torque(torque)
File "/home/john/anaconda3/lib/python3.6/site-packages/pybullet_envs/robot_bases.py", line 387, in set_torque
force=torque)#, positionGain=0.1, velocityGain=0.1)
pybullet.error: Not connected to physics server.

Code: Select all

import gym
import pybullet, pybullet_envs

env = gym.make('InvertedPendulumBulletEnv-v0')
observation = env.reset()

for _ in range(1000):
    env.render()
    action = env.action_space.sample()
    observation, reward, done, info = env.step(action)

    if done:
        observation = env.reset()
    env.close()
I'm using Python 3.6.7 and PyBullet 2.5.2 installed using pip on Ubuntu. Any ideas?

caffett
Posts: 3
Joined: Wed Nov 13, 2019 9:37 pm

Re: Not connected to physics server when trying to run environment

Post by caffett » Wed Nov 13, 2019 9:40 pm

Similar bug.

Code: Select all

# -*- coding: utf-8 -*-
import pybullet as p
import pybullet_envs
import gym


def show_bug():
	env = gym.make("AntBulletEnv-v0")
	print(env.reset())
	print(p.getNumBodies())
	env.step(env.action_space.sample())
	env.close()

	env = gym.make("AntBulletEnv-v0")
	print(env.reset())
	print(p.getNumBodies())
	env.step(env.action_space.sample())
	env.close()
	
	env = gym.make("AntBulletEnv-v0")
	print(p.getNumBodies())
	print(env.reset())
	env.step(env.action_space.sample())
	env.close()

	print("end!")

if __name__ == "__main__":
	show_bug()

caffett
Posts: 3
Joined: Wed Nov 13, 2019 9:37 pm

Re: Not connected to physics server when trying to run environment

Post by caffett » Thu Nov 14, 2019 5:24 am

https://github.com/bulletphysics/bullet ... y#L18-#L22

Comment this code and replace them with a pass, everything will be fine.

The python garbage collection mechanism will not delete the variable immediately. Thus, there will be a delay to call the __del__. When the __del__ is called, it will close the current connection, however, due to the delay, the connection might not be the connection we want to close at begin.

caffett
Posts: 3
Joined: Wed Nov 13, 2019 9:37 pm

Re: Not connected to physics server when trying to run environment

Post by caffett » Thu Nov 14, 2019 5:30 am

Sorry, this just can fix my issue.

Post Reply