code: def main():
      actor_list = []
      pygame.init()
  
      display = pygame.display.set_mode(
          (800, 600), pygame.HWSURFACE | pygame.DOUBLEBUF
      )
      font = get_font()
      clock = pygame.time.Clock()
  
      client = carla.Client("localhost", 2000)
      client.set_timeout(2.0)
  
      world = client.get_world()
  
      try:
          m = world.get_map()
          start_pose = random.choice(m.get_spawn_points())
          waypoint = m.get_waypoint(start_pose.location)
  
          blueprint_library = world.get_blueprint_library()
  
          vehicle = world.spawn_actor(
              random.choice(blueprint_library.filter("vehicle.*")),
              start_pose,
          )
          actor_list.append(vehicle)
          vehicle.set_simulate_physics(False)
  
          camera_rgb = world.spawn_actor(
              blueprint_library.find("sensor.camera.rgb"),
              carla.Transform(
                  carla.Location(x=-5.5, z=2.8),
                  carla.Rotation(pitch=-15),
              ),
              attach_to=vehicle,
          )
          actor_list.append(camera_rgb)
  
          camera_semseg = world.spawn_actor(
              blueprint_library.find(
                  "sensor.camera.semantic_segmentation"
              ),
              carla.Transform(
                  carla.Location(x=-5.5, z=2.8),
                  carla.Rotation(pitch=-15),
              ),
              attach_to=vehicle,
          )
          actor_list.append(camera_semseg)
  
          # Create a synchronous mode context.
          with CarlaSyncMode(
              world, camera_rgb, camera_semseg, fps=30
          ) as sync_mode:
              while True:
                  if should_quit():
                      return
                  clock.tick()
  
                  # Advance the simulation and wait for the data.
                  snapshot, image_rgb, image_semseg = sync_mode.tick(
                      timeout=2.0
                  )
  
                  # Choose the next waypoint and update the car location.
                  waypoint = random.choice(waypoint.next(1.5))
                  vehicle.set_transform(waypoint.transform)
  
                  image_semseg.convert(
                      carla.ColorConverter.CityScapesPalette
                  )
                  fps = round(1.0 / snapshot.timestamp.delta_seconds)
  
                  # Draw the display.
                  draw_image(display, image_rgb)
                  draw_image(display, image_semseg, blend=True)
                  display.blit(
                      font.render(
                          "% 5d FPS (real)" % clock.get_fps(),
                          True,
                          (255, 255, 255),
                      ),
                      (8, 10),
                  )
                  display.blit(
                      font.render(
                          "% 5d FPS (simulated)" % fps,
                          True,
                          (255, 255, 255),
                      ),
                      (8, 28),
                  )
                  pygame.display.flip()
  
      finally:
          print("destroying actors.")
          for actor in actor_list:
              actor.destroy()
  
          pygame.quit()
          print("done.")
  
file_path: carla/PythonAPI/examples/synchronous_mode.py
imports: import glob
  import os
  import sys
  import carla
  import random
label_desc: Use image node_id 4 for calling a global function with example usage: main() without return types