Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tests/complex/traci/misc/concurrent/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
# @author Leonhard Luecken
18
# @date 2010-02-20
19
20
from __future__ import absolute_import
21
from __future__ import print_function
22
23
import os
24
import sys
25
import time
26
import threading
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
34
def traciLoop():
35
print("Starting thread")
36
for step in range(10):
37
traci.simulationStep()
38
# print(index, "asking for vehicles")
39
# sys.stdout.flush()
40
vehs = traci.vehicle.getIDList()
41
print(vehs)
42
# time.sleep(.1)
43
# ~ print(index, "vehs: ", vehs)
44
# ~ sys.stdout.flush()
45
if len(vehs) > 3:
46
print("Something is wrong")
47
time.sleep(.1)
48
print("speed", traci.vehicle.getSpeed(vehs[0]))
49
step += 1
50
print(traci.simulation.getTime())
51
52
53
if __name__ == '__main__':
54
traci.start([sumolib.checkBinary("sumo"), "-c", "sumo.sumocfg"])
55
threads = []
56
for _ in range(3):
57
threads.append(threading.Thread(target=traciLoop))
58
threads[-1].start()
59
for t in threads:
60
t.join()
61
traci.close()
62
63