When are Installation Variables "stored" globally?

We send a small URScript containing

 def setVar():
     global i_test = 123
     socket_open("ip", port)
 end

to set global variables. i_test has been setup manually as an installation variable in PolyScope. When then wait until this back connection is established and start running a saved UR program via the dashboard server. Now sometimes the UR program will still run with the previous variable value. Are we doing something wrong? How can we synchronize setting the variable? Is there a better way to pass arguments to running an ur script stored on the controller? (ur scripts should be as simple as possible since they are intended to be written by end users)

Thanks a lot
Simon