Path: blob/main/tests/complex/traci/connection/repeatedConnection/runner.py
169689 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# @date 2010-02-201718from __future__ import absolute_import19from __future__ import print_function2021import os22import subprocess23import sys2425if "SUMO_HOME" in os.environ:26sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))27import sumolib # noqa28import traci # noqa2930PORT = sumolib.miscutils.getFreeSocketPort()31sumoBinary = sumolib.checkBinary(sys.argv[1])323334def runSingle(sumoEndTime, traciEndTime):35fdi = open("sumo.sumocfg")36fdo = open("used.sumocfg", "w")37fdo.write(fdi.read() % {"end": sumoEndTime})38fdi.close()39fdo.close()40step = 041sumoProcess = subprocess.Popen(42"%s -c used.sumocfg -S -Q --remote-port %s" % (sumoBinary, PORT), shell=True, stdout=sys.stdout)43traci.init(PORT)44while not step > traciEndTime:45traci.simulationStep()46vehs = traci.vehicle.getIDList()47if vehs.index("horiz") < 0 or len(vehs) > 3:48print("Something is wrong")49step += 150print("Print ended at step %s" % traci.simulation.getTime())51traci.close()52sumoProcess.wait()53sys.stdout.flush()545556print("----------- SUMO ends first -----------")57sys.stdout.flush()58for i in range(0, 10):59print(" Run %s" % i)60runSingle(50, 99)6162print("----------- TraCI ends first -----------")63sys.stdout.flush()64for i in range(0, 10):65print(" Run %s" % i)66runSingle(101, 99)676869