Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[sumo-user] Multiple SUMO instances with TraCI/Python threads

Dear all,

in our recent project we need to run quite a number of simulations (we are simulating different charging strategies for e-buses and partial trolleybuses and the influence of traffic conditions on delays and stability of the timetable). In order to keep the simulation running in an unattended manner, and as I need to modify certain aspects of the simulation online, I am currently running the simulations sequentially using TraCI/Python interface.

As the simulations take some time and I am becoming less and less patient, I am moving the computation to one of our numbercruncher servers and I would like to run the whole simulation batch in a multithreaded manner, with every worker thread running a sequence of several sumo simulations with configurations fetched from a global queue.

I am not quite sure if TraCI/Python supports interaction with multiple SUMO instances from one Python script -- googling and looking into archives I was only able to find some discussions related to multiple threads communicating with a single SUMO instance. I am aware that starting SUMO via TraCI ist not a thread-safe operation, and I vaguely remember a notice somewhere stating that once the TraCI connection is made inside a thread, subsequent TraCI/Python operations should use the thread-based connection, but I am not sure about that.

So my question is: Will something like this work?

----- thread 1 -----
[... get the job from the global queue ...]
lock_traci()
traci.start(sumo_cmd_with_config_1, port=port_1)
unlock_traci()
while step < last_step:
    traci.simulationStep()
    step += 1
traci.close()

----- thread 2 -----
[... get the job from the global queue ...]
lock_traci()
traci.start(sumo_cmd_with_config_2, port=port_2)
unlock_traci()
while step < last_step:
    traci.simulationStep()
    step += 1
traci.close()

Or do I need to label the connections, call `conn = traci.getConnection(thread_label)` and use `conn` instead of `traci` (it definitely looks cleaner to me, but I am not sure what is the preferred way)?

Thanks!

-- 
Jan Přikryl
RICE FEL UWB  & CTU FTS


Back to the top