Hi everyone

Trying to open two simulations with the same port hangs the entire
execution, instead of raising an exception

Error
"Error: tcpip::Socket::accept() Unable to create listening socket: Address
already in use
Quitting (on error)."


I'm currently running several experiments, simultaneously, in isolated
docker containers. And inside every experiment, running several parallel
simulations

The problem is that my experiments can step (and eventually does) into
address conflict problems (race condition) and the hanging prevents any
chance of retrying it with a new port, suspending the entire experiment
forever.

The use of synchronization locks prevents address conflicts inside one
experiment, so I'm basically limited to run one experiment at a time, which
is very time consuming.


As a workaround, I'm going to specify port ranges for each simulation and
check it for availability

Let me know if there is a better solution as workaround

And thank you in advance


P.S. I've included a trivial example to show the hanging behavior, but
there is nothing special about it.


Sincerely,

Marcelo d'Almeida
 
import os
import sys

if 'SUMO_HOME' in os.environ:
    tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
    sys.path.append(tools)
else:
    sys.exit("please declare environment variable 'SUMO_HOME'")

from os.path import expanduser

import traci
from sumolib import checkBinary

home = expanduser("~")

sys.path.append('traffic-light-optimization')


def get_sumo_binary(gui=False):

    if gui:
        sumo_binary = checkBinary('sumo-gui')
    else:
        sumo_binary = checkBinary('sumo')

    return sumo_binary

class Example:

    def __init__(self, net_file, route_file):

        self.net_file = net_file
        self.route_file = route_file

    def start_traci(self, gui=False):
        traci.start([
            get_sumo_binary(gui),
            '-n', self.net_file,
            '-r', self.route_file
        ], port=30000)

    def run_inner_model(self, label, initial_step):
        print('starting')
        gui = False

        from utils import sumo_util

        save_state = home + '/temp/simulation_state'
        time = initial_step

        net_xml = sumo_util.get_xml(self.net_file)
        stops_to_issue = sumo_util.fix_save_state_stops(net_xml, save_state, time)

        traci.start([
            get_sumo_binary(gui),
            '-n', self.net_file,
            '-r', self.route_file,
            '--start', str(True),
            '--quit-on-end', str(True),
            '--begin', str(initial_step),
            '--load-state', home + '/temp/simulation_state'
        ], label=label, port=30000)

        traci_connection = traci.getConnection(label)

        for stop_info in stops_to_issue:
            traci_connection.vehicle.setStop(**stop_info)

        i = 10
        while traci_connection.simulation.getMinExpectedNumber() > 0:
            traci_connection.simulationStep()

            if i == 0:
                break

            i -= 1

        traci_connection.close()
        traci.switch('default')

    def run_simulation(self):

        while traci.simulation.getMinExpectedNumber() > 0:

            step = traci.simulation.getTime()

            if step % 10 == 0:

                traci.simulation.saveState(home + '/temp/simulation_state')

                try:
                    traci.start([
                        get_sumo_binary(False),
                        '-n', self.net_file,
                        '-r', self.route_file,
                        '--start', str(True),
                        '--quit-on-end', str(True),
                        '--begin', str(step),
                        '--load-state', home + '/temp/simulation_state'
                    ], label=0, port=30000)
                except Exception as e:
                    print(str(e))

                traci_connection = traci.getConnection(0)

            traci.simulationStep()


net_file = home + '/temp/regular-intersection__right_on_red.net.xml'
route_file = home + '/temp/regular-intersection.rou.xml'

example = Example(net_file, route_file)
example.start_traci()
example.run_simulation()
traci.close()


<<attachment: temp.zip>>

_______________________________________________
sumo-user mailing list
[email protected]
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/sumo-user

Reply via email to