carla
carla copied to clipboard
Can not kill Carla by Python script when i set autopilot mode
I am using CARLA 0.9.15 in Ubuntu 18.04 I write a python script to open carla、spawn vehicle、set autopilot、kill carla... repeatedly. But when i kill carla for the first round, error meassage was raised: aborted (core dumped). The weird thing is if i do not set autopilot, then the circulation can run, which is open carla、spawn vehicle、kill carla... My brief codes is as follows:
def find_and_kill_process(name, user=None):
for proc in psutil.process_iter(['pid', 'name', 'username']):
try:
if user and proc.info['username'] != user:
continue
if name in proc.info['name']:
print(proc.info['pid'], proc.info['name'])
proc.kill()
print("force terminate process")
proc.wait()
print("wait process close")
print(f"Process with PID {proc.info['pid']} ({proc.info['name']}) terminated.")
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
def main():
try:
carla_server_path = '/home/user_name/CARLA/CarlaUE4.sh'
subprocess.Popen(carla_server_path)
time.sleep(5.0)
client = carla.Client('localhost', 2000)
world = client.load_world("Town04")
x = random.choice([-337, -331, -325, -319])
y = random.choice([26, 29.5, 33, 36.5])
ego_location = carla.Location(x, y, z=3)
ego_rotation = carla.Rotation(yaw=0)
ego_spawn_point = carla.Transform(ego_location, ego_rotation)
ego_bp = world.get_blueprint_library().find('vehicle.audi.etron')
ego_bp.set_attribute('role_name', 'CAV')
ego_vehicle = world.spawn_actor(ego_bp, ego_spawn_point)
world.tick()
ego_vehicle.set_autopilot(True) **# if delete this line, then the the script will run successfully**
i = 0
while True:
i += 1
time.sleep(1.0)
if i == 5:
break
spectator = world.get_spectator()
spectator_location = carla.Location(ego_vehicle.get_location().x, ego_vehicle.get_location().y, ego_vehicle.get_location().z + 100)
spectator_rotation = carla.Rotation(pitch=-90)
spectator_transform = carla.Transform(spectator_location, spectator_rotation)
spectator.set_transform(spectator_transform)
except:
pass
if __name__ == '__main__':
for i in range(20):
print(f"______________episode {i}__________________")
main()
find_and_kill_process("CarlaUE4-Linux-Shipping", "user_name")