Path: blob/main/tests/complex/traci/connection/busySocket/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# @date 2011-03-021718from __future__ import absolute_import19from __future__ import print_function2021import os22import subprocess23import sys24import shutil25import socket2627if "SUMO_HOME" in os.environ:28sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))29import sumolib # noqa30import traci # noqa3132sumoBinary = sumolib.checkBinary(sys.argv[1])33if sys.argv[1] == "sumo":34addOption = ["-c", "sumo.sumocfg"]35else:36addOption = ["-S", "-Q", "-c", "sumo_log.sumocfg"]37PORT = sumolib.miscutils.getFreeSocketPort()38s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)39s.bind(('', PORT))4041sumoProc = subprocess.Popen([sumoBinary, "--remote-port", str(PORT)] + addOption,42stdout=sys.stdout)43try:44traci.init(PORT, numRetries=5)45traci.close()46except traci.FatalTraCIError as e:47print(e, file=sys.stderr)48sumoProc.wait()49sys.stdout.flush()50if os.path.exists("lastrun.stderr"):51f = open("lastrun.stderr")52shutil.copyfileobj(f, sys.stderr)53f.close()54s.close()555657