Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/traci/connection/busySocket/runner.py
169708 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file runner.py
15
# @author Daniel Krajzewicz
16
# @author Michael Behrisch
17
# @date 2011-03-02
18
19
from __future__ import absolute_import
20
from __future__ import print_function
21
22
import os
23
import subprocess
24
import sys
25
import shutil
26
import socket
27
28
if "SUMO_HOME" in os.environ:
29
sys.path.append(os.path.join(os.environ["SUMO_HOME"], "tools"))
30
import sumolib # noqa
31
import traci # noqa
32
33
sumoBinary = sumolib.checkBinary(sys.argv[1])
34
if sys.argv[1] == "sumo":
35
addOption = ["-c", "sumo.sumocfg"]
36
else:
37
addOption = ["-S", "-Q", "-c", "sumo_log.sumocfg"]
38
PORT = sumolib.miscutils.getFreeSocketPort()
39
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
40
s.bind(('', PORT))
41
42
sumoProc = subprocess.Popen([sumoBinary, "--remote-port", str(PORT)] + addOption,
43
stdout=sys.stdout)
44
try:
45
traci.init(PORT, numRetries=5)
46
traci.close()
47
except traci.FatalTraCIError as e:
48
print(e, file=sys.stderr)
49
sumoProc.wait()
50
sys.stdout.flush()
51
if os.path.exists("lastrun.stderr"):
52
f = open("lastrun.stderr")
53
shutil.copyfileobj(f, sys.stderr)
54
f.close()
55
s.close()
56
57