Path: blob/main/tests/complex/traci/misc/concurrent/runner.py
169708 views
#!/usr/bin/env python1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.3# This program and the accompanying materials are made available under the4# terms of the Eclipse Public License 2.0 which is available at5# https://www.eclipse.org/legal/epl-2.0/6# This Source Code may also be made available under the following Secondary7# Licenses when the conditions for such availability set forth in the Eclipse8# Public License 2.0 are satisfied: GNU General Public License, version 29# or later which is available at10# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1213# @file runner.py14# @author Daniel Krajzewicz15# @author Michael Behrisch16# @author Leonhard Luecken17# @date 2010-02-201819from __future__ import absolute_import20from __future__ import print_function2122import os23import sys24import time25import threading2627if "SUMO_HOME" in os.environ:28sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))29import sumolib # noqa30import traci # noqa313233def traciLoop():34print("Starting thread")35for step in range(10):36traci.simulationStep()37# print(index, "asking for vehicles")38# sys.stdout.flush()39vehs = traci.vehicle.getIDList()40print(vehs)41# time.sleep(.1)42# ~ print(index, "vehs: ", vehs)43# ~ sys.stdout.flush()44if len(vehs) > 3:45print("Something is wrong")46time.sleep(.1)47print("speed", traci.vehicle.getSpeed(vehs[0]))48step += 149print(traci.simulation.getTime())505152if __name__ == '__main__':53traci.start([sumolib.checkBinary("sumo"), "-c", "sumo.sumocfg"])54threads = []55for _ in range(3):56threads.append(threading.Thread(target=traciLoop))57threads[-1].start()58for t in threads:59t.join()60traci.close()616263